Craig Hopson Posted February 20, 2013 Share Posted February 20, 2013 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) 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 Link to comment Share on other sites More sharing options...
0 Argi Posted February 20, 2013 Share Posted February 20, 2013 What's the current output? You also should initialize $fab = array(). Link to comment Share on other sites More sharing options...
0 Craig Hopson Posted February 20, 2013 Author Share Posted February 20, 2013 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 ) ) Link to comment Share on other sites More sharing options...
0 tim_s Posted February 20, 2013 Share Posted February 20, 2013 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? Link to comment Share on other sites More sharing options...
0 Jose_49 Posted February 20, 2013 Share Posted February 20, 2013 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 ) ) 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>') Link to comment Share on other sites More sharing options...
0 Craig Hopson Posted February 20, 2013 Author Share Posted February 20, 2013 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 ) ) ) Link to comment Share on other sites More sharing options...
0 tim_s Posted February 20, 2013 Share Posted February 20, 2013 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 ) ) ) 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. Link to comment Share on other sites More sharing options...
0 Craig Hopson Posted February 20, 2013 Author Share Posted February 20, 2013 sorry my bad i had the echo '<pre>'; echo print_r($fab); echo '</pre>'; in the while {} SORRY :s Link to comment Share on other sites More sharing options...
0 tim_s Posted February 20, 2013 Share Posted February 20, 2013 sorry my bad i had the echo '<pre>'; echo print_r($fab); echo '</pre>'; in the while {} SORRY :s Glad to have been of help ;) Link to comment Share on other sites More sharing options...
Question
Craig Hopson
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)
Thanks
Link to comment
Share on other sites
8 answers to this question
Recommended Posts