kampbell411 Posted May 22, 2010 Share Posted May 22, 2010 I've been going crazy on how to figure this out. Kinda new to php. I'm trying to get array results outside of a while loop. Im basically trying to put my results into an array and then set those array values as a variable to use outside of while loop. Im trying to load addresses into a jquery plugin that plots multiple points. I wanted to get the addresses from DB then store in variable with the addresses and use that variable in my javascript. $sql = "SELECT zip, state, city FROM $tbl_name WHERE state = 'value'; $result = mysql_query($sql); while($row = mysql_fetch_array($result)) { $zip = $row->zip; $state = $row->state; $city = $row->city; $newzip= $row['zip']; $addresses = array( array("address"=>$newzip), ); } echo $addresses; <---would like to do something like that with all the values put in $addresses the array Link to comment https://forums.phpfreaks.com/topic/202583-getting-array-values-and-using-outside-while-loop/ Share on other sites More sharing options...
kenrbnsn Posted May 22, 2010 Share Posted May 22, 2010 Try something like this: <?php $sql = "SELECT zip, state, city FROM $tbl_name WHERE state = 'value'"; $result = mysql_query($sql); $addresses = array(); while($row = mysql_fetch_assoc($result)) { $addresses[] = $row['city'] . ', ' . $row['state'] . ' ' . $row['zip']; } echo implode("<br>\n", $addresses); // print what's in the array // // or // echo '<pre>' . print_r($addresses,true) . '</pre>'; // just dump them ?> Ken Link to comment https://forums.phpfreaks.com/topic/202583-getting-array-values-and-using-outside-while-loop/#findComment-1061979 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.