mazman13 Posted October 29, 2007 Share Posted October 29, 2007 Will something like this work to create an array in a loop? $query = "SELECT DISTINCT writer FROM data"; $result = mysql_query($query) or die ("Can't do anything with the query!"); while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) { extract($row); $servicewriters = array($writer); } echo"$servicewriters[1]"; Link to comment https://forums.phpfreaks.com/topic/75255-solved-can-i-create-arrays-in-loops/ Share on other sites More sharing options...
micah1701 Posted October 29, 2007 Share Posted October 29, 2007 it should work but you'll re-write the array each time you go through the loop. why not test it and see what it does? Link to comment https://forums.phpfreaks.com/topic/75255-solved-can-i-create-arrays-in-loops/#findComment-380644 Share on other sites More sharing options...
kenrbnsn Posted October 29, 2007 Share Posted October 29, 2007 That will not do what I think you want, which is probably an array holding all the values of the field "writer" in the selected rows. This code will do that: <?php $query = "SELECT DISTINCT writer FROM data"; $result = mysql_query($query) or die ("Can't do anything with the query!"); $servicewriters = array(); while ($row = mysql_fetch_assoc($result)) $servicewriters[] = $row['writer']; echo '<pre>' . print_r($servicewriters,true) . '</pre>'; ?> Ken Link to comment https://forums.phpfreaks.com/topic/75255-solved-can-i-create-arrays-in-loops/#findComment-380647 Share on other sites More sharing options...
mazman13 Posted October 29, 2007 Author Share Posted October 29, 2007 It works! Thanks! Link to comment https://forums.phpfreaks.com/topic/75255-solved-can-i-create-arrays-in-loops/#findComment-380652 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.