Forum Moderators: phranque
Do i put it on top of the page before the ordinary html tag begins or what..
<html>
<head> </head>
</html>
<?php
// execute database query and build list:
$select_list = '';
$sql = "SELECT list_item FROM table";
$rows = mysql_query($sql);
if (mysql_num_rows($rows) <> 0) {
while ($row = mysql_fetch_assoc($rows)) {
$select_list .= "<option value=\"" . htmlentities($row['list_item']) . '"';
if ($list_item == $row['list_item']) $select_list .= ' selected="selected"';
$select_list .= '>' . htmlentities($row['list_item']). '</option>';
}
}
mysql_free_result($rows);
?>
<html>
<head>
...
<form>
<select><?php print $select_list;?></select>
...
</html>
Generally I put everything script related above the <html> tag, but sometimes I need to loop through records, and use those values to call another recordset, so I'll have a connection/recrdset right in the middle of the page.
Remember, any scripting code is processed before the finished page is rendered.