Forum Moderators: coopster
i am trying to create a drop down box which references to a mysql database for its options.
So far i have managed to get the Box working by manually putting in the php in the option commands eg...
<select name="select1" styple="width:300">
<option><?php ........ limit 0,1 orderby date DESC?></option>
<option><?php ........ limit 1,1 orderby date DESC?></option>
</select>
The problem with this is if you allow for more inputes to be entered into the list later on you get loads of blank options.
Does anyone know of a way to make php automatically insert a new option if it exists in the database?
Any help on this would be most appreciated
thankyou
<select name="select1" style="width:300">
<?php
if (!$link = mysql_connect('localhost', 'root')) {
echo 'Could not connect to mysql';
exit;
}
if (!mysql_select_db('reports', $link)) {
echo 'Could not select database';
exit;
}
$sql = 'SELECT * FROM comments1 order by added DESC limit 1,1';
$result = mysql_query($sql, $link);
if (!$result) {
echo "DB Error, could not query the database\n";
echo 'MySQL Error: ' . mysql_error();
exit;
}
while (mysql_fetch_row($result)) {
echo "<option>$row['comment']</option>";
}
?>
</select>
and am getting this error :
Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in c:\inetpub\wwwroot\Reports\comment1chooser.php3 on line 35
Can anyone shed some light on this one?
thankyou for all the help so far!