Jump to content
  • 0

Question

Posted

hi guys i have a simple one ui cant solve i want an array to be like this

Array (
[0] => Array (
[id] => 2
[lat] => 40.8824996948
[long] => -74.381942749
)
[1] => Array (
[id] => 6
[lat] => 40.8824996948
[long] => -74.381942749
)
[2] => Array (
[id] => 4
[lat] => 51.5001525879
[long] => -0.126236006618 )
)
)

This is the code i'm using which gives me multipuls of arrays (as it's looping)
[CODE]
include('modules/fab/ip2location.class.php');
$ip = new ip2location;
$ip->open('modules/fab/databases/IP-COUNTRY-REGION-CITY-LATITUDE-LONGITUDE-SAMPLE.BIN');
$uid = $client['id'];
$result = sql_query("SELECT * FROM `jcow_accounts` where ipaddress != '' order by lastlogin desc ");
$i = 0;
while($row = mysql_fetch_array($result)) {

$record = $ip->getAll($row['ipaddress']);
$id = $row['id'];
$lat = $record->latitude;
$long = $record->longitude;

$fab[] = array(
'id'=>$id,
'lat'=>$lat,
'long'=>$long,
);
}
[/CODE]

Thanks

Share this post


Link to post
Share on other sites

8 answers to this question

  • 0

Posted

What's the current output? You also should initialize $fab = array().

Share this post


Link to post
Share on other sites
  • 0

Posted

forgive me for not formatting it but this is wat i get

Array ( [0] => Array ( [id] => 2 [lat] => 40.8824996948 [long] => -74.381942749 ) ) Array ( [0] => Array ( [id] => 2 [lat] => 40.8824996948 [long] => -74.381942749 ) [1] => Array ( [id] => 6 [lat] => 40.8824996948 [long] => -74.381942749 ) ) Array ( [0] => Array ( [id] => 2 [lat] => 40.8824996948 [long] => -74.381942749 ) [1] => Array ( [id] => 6 [lat] => 40.8824996948 [long] => -74.381942749 ) [2] => Array ( [id] => 4 [lat] => 51.5001525879 [long] => -0.126236006618 ) ) Array ( [0] => Array ( [id] => 2 [lat] => 40.8824996948 [long] => -74.381942749 ) [1] => Array ( [id] => 6 [lat] => 40.8824996948 [long] => -74.381942749 ) [2] => Array ( [id] => 4 [lat] => 51.5001525879 [long] => -0.126236006618 ) [3] => Array ( [id] => 5 [lat] => 40.8824996948 [long] => -74.381942749 ) ) Array ( [0] => Array ( [id] => 2 [lat] => 40.8824996948 [long] => -74.381942749 ) [1] => Array ( [id] => 6 [lat] => 40.8824996948 [long] => -74.381942749 ) [2] => Array ( [id] => 4 [lat] => 51.5001525879 [long] => -0.126236006618 ) [3] => Array ( [id] => 5 [lat] => 40.8824996948 [long] => -74.381942749 ) [4] => Array ( [id] => 3 [lat] => 51.5001525879 [long] => -0.126236006618 ) )

Share this post


Link to post
Share on other sites
  • 0

Posted

Formatted example,

#
# ITERATION 1
#

Array (
[0] => Array (
[id] => 2
[lat] => 40.8824996948
[long] => -74.381942749
)
)

#
# ITERATION 2 (which includes iteration 1)
#

Array (
[0] => Array (
[id] => 2
[lat] => 40.8824996948
[long] => -74.381942749
)
[1] => Array (
[id] => 6
[lat] => 40.8824996948
[long] => -74.381942749
)
)


#
# QUESTION
#

Are you printing the contents of the array while within the while loop?

Share this post


Link to post
Share on other sites
  • 0

Posted

[quote name='Craig Hopson' timestamp='1361391915' post='595532930']
forgive me for not formatting it but this is wat i get

Array ( [0] => Array ( [id] => 2 [lat] => 40.8824996948 [long] => -74.381942749 ) ) Array ( [0] => Array ( [id] => 2 [lat] => 40.8824996948 [long] => -74.381942749 ) [1] => Array ( [id] => 6 [lat] => 40.8824996948 [long] => -74.381942749 ) ) Array ( [0] => Array ( [id] => 2 [lat] => 40.8824996948 [long] => -74.381942749 ) [1] => Array ( [id] => 6 [lat] => 40.8824996948 [long] => -74.381942749 ) [2] => Array ( [id] => 4 [lat] => 51.5001525879 [long] => -0.126236006618 ) ) Array ( [0] => Array ( [id] => 2 [lat] => 40.8824996948 [long] => -74.381942749 ) [1] => Array ( [id] => 6 [lat] => 40.8824996948 [long] => -74.381942749 ) [2] => Array ( [id] => 4 [lat] => 51.5001525879 [long] => -0.126236006618 ) [3] => Array ( [id] => 5 [lat] => 40.8824996948 [long] => -74.381942749 ) ) Array ( [0] => Array ( [id] => 2 [lat] => 40.8824996948 [long] => -74.381942749 ) [1] => Array ( [id] => 6 [lat] => 40.8824996948 [long] => -74.381942749 ) [2] => Array ( [id] => 4 [lat] => 51.5001525879 [long] => -0.126236006618 ) [3] => Array ( [id] => 5 [lat] => 40.8824996948 [long] => -74.381942749 ) [4] => Array ( [id] => 3 [lat] => 51.5001525879 [long] => -0.126236006618 ) )
[/quote]
I want to share with you an amazing trick I've learned for printing out the array:
Add this:
print('<pre>')
print_r($put_the_variable_name_you_want_to_display);
print('</pre>')

Share this post


Link to post
Share on other sites
  • 0

Posted

my whole script is above i've just started the project basicly i will have about 100 entrys in the array like this

Array (
[0] => Array (
[id] => 2
[lat] => 40.8824996948
[long] => -74.381942749
)
[1] => Array (
[id] => 6
[lat] => 40.8824996948
[long] => -74.381942749
)
[2] => Array (
[id] => 4
[lat] => 51.5001525879
[long] => -0.126236006618 )
)
)

Share this post


Link to post
Share on other sites
  • 0

Posted

[quote name='Craig Hopson' timestamp='1361393184' post='595532982']
my whole script is above i've just started the project basicly i will have about 100 entrys in the array like this

Array (
[0] => Array (
[id] => 2
[lat] => 40.8824996948
[long] => -74.381942749
)
[1] => Array (
[id] => 6
[lat] => 40.8824996948
[long] => -74.381942749
)
[2] => Array (
[id] => 4
[lat] => 51.5001525879
[long] => -0.126236006618 )
)
)
[/quote]

Ok! But the code appears to be doing this outside of the fact with each iteration it is including results from the previous, which is what would happen if you are dumping the contents of the array WHILE within the `while` loop.

Share this post


Link to post
Share on other sites
  • 0

Posted

sorry my bad i had the

echo '<pre>';
echo print_r($fab);
echo '</pre>';

in the while {}

SORRY :s

Share this post


Link to post
Share on other sites
  • 0

Posted

[quote name='Craig Hopson' timestamp='1361393426' post='595532994']
sorry my bad i had the

echo '<pre>';
echo print_r($fab);
echo '</pre>';

in the while {}

SORRY :s
[/quote]

Glad to have been of help ;)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.