Johnnyboy123 Posted April 28, 2011 Share Posted April 28, 2011 Name says it all. I have a form and 2 tables that are going to have to be linked with each other. Although what I'm trying to do now is very basic and I'm struggling haha Though this is my first php project Basicly I got a form with a drop down menu, which I want to display the contents of my table (course) which the user then selects from and submits to another table (student) Here is my code for this part <?php <?php $q = "SELECT cname FROM course "; $result = mysql_query($q); $course = mysql_fetch_array($result); ?> <div id="apdiv3"> <FORM action = "demo.php" method ="post"> <p>Course name:</p> <select name="cname"> <OPTION> <?php echo $course['cname']; ?> </option> </SELECT> ?> It only displays 1 item from my course table. What am I doing wrong? And also please explain so I can learn from my mistakes Quote Link to comment https://forums.phpfreaks.com/topic/234978-trying-to-get-form-to-display-table-content-on-drop-down/ Share on other sites More sharing options...
Muddy_Funster Posted April 28, 2011 Share Posted April 28, 2011 You are only selecting the top level result that is returned in the array. You will need to run through the array in order to get what you want out. <div id="apdiv3"> <FORM action = "demo.php" method ="post"> <p>Course name:</p> <select name="cname"> <?php $q = "SELECT cname FROM course "; $result = mysql_query($q); WHILE ($course = mysql_fetch_array($result)){ echo "<OPTION> value='{$course['cname']}'>{$cource['cname']}</option>"; } echo " </SELECT>" Should do it. You also need to look into how to form <option>'s better. Quote Link to comment https://forums.phpfreaks.com/topic/234978-trying-to-get-form-to-display-table-content-on-drop-down/#findComment-1207580 Share on other sites More sharing options...
quelle Posted April 28, 2011 Share Posted April 28, 2011 Just add the opperator "." before "=" cuz like this you are going trough ur db results and displaying only last one ! Quote Link to comment https://forums.phpfreaks.com/topic/234978-trying-to-get-form-to-display-table-content-on-drop-down/#findComment-1207589 Share on other sites More sharing options...
Muddy_Funster Posted April 28, 2011 Share Posted April 28, 2011 Just add the opperator "." before "=" cuz like this you are going trough ur db results and displaying only last one ! erm...now your just being silly. Quote Link to comment https://forums.phpfreaks.com/topic/234978-trying-to-get-form-to-display-table-content-on-drop-down/#findComment-1207600 Share on other sites More sharing options...
Johnnyboy123 Posted April 28, 2011 Author Share Posted April 28, 2011 Ah I see. Working fine now. Thanks alot guys Quote Link to comment https://forums.phpfreaks.com/topic/234978-trying-to-get-form-to-display-table-content-on-drop-down/#findComment-1207606 Share on other sites More sharing options...
Muddy_Funster Posted April 28, 2011 Share Posted April 28, 2011 No worries, remember to mark as solved (bottom left of the page) Quote Link to comment https://forums.phpfreaks.com/topic/234978-trying-to-get-form-to-display-table-content-on-drop-down/#findComment-1207609 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.