Andrew R Posted August 4, 2007 Share Posted August 4, 2007 Hi Sorry for the unclear topic title. I'm trying to display all the results from a database and use echo them using $total. $total = do { "".$row_use['lon']." ".$row_use['lat']."" } while ($row_use = mysql_fetch_assoc($use)); echo $total; I was wondering why does that not work? How do I get the php repeated regions to work? Link to comment https://forums.phpfreaks.com/topic/63317-gathering-results-and-echoing-them-as-one/ Share on other sites More sharing options...
purefan Posted August 4, 2007 Share Posted August 4, 2007 a do-while loop is not what you want here, you want a regular while, something like: while($row = mysql_fetch_array($result,MYSQL_ASSOC)) { $total .= "$row[lon] $row[lat]; } Link to comment https://forums.phpfreaks.com/topic/63317-gathering-results-and-echoing-them-as-one/#findComment-315528 Share on other sites More sharing options...
Andrew R Posted August 4, 2007 Author Share Posted August 4, 2007 Thanks. The thing is I have alot about hundred entries in the database and I want them to appear like in that order $row_use['lon']; $row_use['lat']; repeating itself? Link to comment https://forums.phpfreaks.com/topic/63317-gathering-results-and-echoing-them-as-one/#findComment-315535 Share on other sites More sharing options...
dbo Posted August 4, 2007 Share Posted August 4, 2007 while($row = mysql_fetch_array($result,MYSQL_ASSOC)) { echo $row[lon] . " " . $row[lat] . "<br />"; } ? Link to comment https://forums.phpfreaks.com/topic/63317-gathering-results-and-echoing-them-as-one/#findComment-315572 Share on other sites More sharing options...
Andrew R Posted August 4, 2007 Author Share Posted August 4, 2007 Thanks very much How would I now grab all those results so I could echo them all with some echo like echo $total somewhere else on the page? Link to comment https://forums.phpfreaks.com/topic/63317-gathering-results-and-echoing-them-as-one/#findComment-315591 Share on other sites More sharing options...
pyrodude Posted August 4, 2007 Share Posted August 4, 2007 The $result variable would be available to the whole page. What I would suggest is adding the while loop to a function that receives $result as a parameter, and then call the function on the page where you need it. Link to comment https://forums.phpfreaks.com/topic/63317-gathering-results-and-echoing-them-as-one/#findComment-315611 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.