mjcoco Posted May 4, 2008 Share Posted May 4, 2008 Im trying to auto populate a list box with information that is in the database. The problem im running into is that im only displaying 1 of the elements not all of them. <? session_start(); include("database.php"); function displayProf() { global $conn; $q = "select * from members"; $result = mysql_query($q,$conn); $row = mysql_fetch_array($result); $coun = mysql_num_rows( $result ); for($i = 0; $i < $coun; $i++) { echo $row[4]; } } ?> of course i realize this isnt putting anything into the combo box but i want it to display all the info before i put it in there. Quote Link to comment Share on other sites More sharing options...
Caesar Posted May 4, 2008 Share Posted May 4, 2008 Use a while loop instead. Quote Link to comment Share on other sites More sharing options...
rarebit Posted May 4, 2008 Share Posted May 4, 2008 echo $row[4]; needs to be... echo $row[$i]; Quote Link to comment Share on other sites More sharing options...
mjcoco Posted May 4, 2008 Author Share Posted May 4, 2008 Maybe i wasnt clear, what i have is a table of members. And what im wanting is say for all of thier first names to display. If i use $i, it just displays the entire row. Quote Link to comment Share on other sites More sharing options...
rarebit Posted May 4, 2008 Share Posted May 4, 2008 Right, I thought you were abreviating, here's an example: while ($a = mysql_fetch_array($res)) { print $a['id'].": ".$a['name']." - ".$a['pass']."<br>"; } Quote Link to comment Share on other sites More sharing options...
mjcoco Posted May 4, 2008 Author Share Posted May 4, 2008 Your the man rarebit worked like a champ. 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.