<?php include 'config.php'; include 'opendb.php'; $sql="SELECT id, name FROM Sites"; $result=mysql_query($sql); $options=""; while ($row=mysql_fetch_array($result)) { $id=$row["id"]; $name=$row["name"]; $options.="<OPTION VALUE=\"$id\">".$name; } ?> <html> <body> <form action="update.php" method="post"> <SELECT NAME=id> <OPTION VALUE=$id>Choose <?=$options?> </SELECT> <input type="submit" value="Submit" /> </form> </body> </html> Code (markup): $options.="<OPTION VALUE=\"$id\">".$name; need explanation of this line
I believe it should be: <?php include 'config.php'; include 'opendb.php'; $sql="SELECT id, name FROM Sites"; $result=mysql_query($sql); $options=""; while ($row=mysql_fetch_array($result)) { $id=$row["id"]; $name=$row["name"]; $options.="<OPTION VALUE=\"$id\">".$name."</option>"; } ?> <html> <body> <form action="update.php" method="post"> <SELECT NAME=id> <OPTION VALUE=$id>Choose <?=$options?> </SELECT> <input type="submit" value="Submit" /> </form> </body> </html> Code (markup): this code $options.="<OPTION VALUE=\"$id\">".$name."</option>"; put all the values found to the <option></option> tag .= is a shortcut to to $options = $options."<OPTION VALUE=\"$id\">".$name."</option>"; Code (markup): hope this helps
$options.="<OPTION VALUE=\"$id\">".$name."</OPTION>"; You should have a closing option tag for each of the options. It should work fine, if rest of the code runs well.
it is called concat equals, meaning string variable '$options' can be elongated with more following '$options' variable, without the .= symbol, the variable will be overwritten with the last $options initialized.