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. Link to comment https://forums.phpfreaks.com/topic/104095-solved-question-on-displaying-table-mysql/ Share on other sites More sharing options...
Caesar Posted May 4, 2008 Share Posted May 4, 2008 Use a while loop instead. Link to comment https://forums.phpfreaks.com/topic/104095-solved-question-on-displaying-table-mysql/#findComment-532880 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]; Link to comment https://forums.phpfreaks.com/topic/104095-solved-question-on-displaying-table-mysql/#findComment-532881 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. Link to comment https://forums.phpfreaks.com/topic/104095-solved-question-on-displaying-table-mysql/#findComment-532885 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>"; } Link to comment https://forums.phpfreaks.com/topic/104095-solved-question-on-displaying-table-mysql/#findComment-532891 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!!!! Link to comment https://forums.phpfreaks.com/topic/104095-solved-question-on-displaying-table-mysql/#findComment-532951 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.