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]"; Quote Link to comment 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? Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
mazman13 Posted October 29, 2007 Author Share Posted October 29, 2007 It works! Thanks! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.