php - How to create select option from database? -


i'm working on form has 4 different select elements 2 tables of database. haven't done , don't know how it.

i have table called "students" need "name" , "class" , table called "books" need "writer" "title" ... 1 select element , has more 2 option values.

i've tried 1 sql query , 1 select shows 1 option on site, wether has 6 values in database.

my code:

$sql = "select class         students"; $result = mysql_query($sql);   while ($row = mysql_fetch_assoc($result)) {     $select_class = "<option value={$row['class']}>{$row['class']}</option>"; }  <select id="class" name="class">     <?php print $select_class; ?> </select> 

how correct?

you overwriting $select_class on each while() loop. need concatenate $select_class . change $select_class .=

$select_class = ""; while ($row = mysql_fetch_assoc($result)) {     $select_class .= "<option value={$row['class']}>{$row['class']}</option>"; } 

Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -