blueuniverse
07-23-2008, 06:05 PM
I have a piece of code
$result = mysql_query("SELECT * FROM category")
or die(mysql_error());
echo "<select name='catid' id='catid'>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
// Print out the contents of each row into a table
echo "<option value='".$row['id']."'>";
echo $row['category'];
echo "</option>";
echo "\n";
This is fine for an upload form (where I've got it from) but not for an edit form. I need it to haev selected=selected by the option that matches my category id.
Just for reference the outputted html of the above is
<select name='catid' id='catid'><option value='1'>Cat1</option>
<option value='2'>Cat2</option>
<option value='3'>Cat3</option>
<option value='4'>Cat4</option>
</select>
My script is getting the recordid and calling it $id
It's then doing a sql select
$sql = "SELECT * FROM library WHERE id=$id";
I want it to grab the catid from this (catid being a field in the table) and then add selected=selected in the initial code I posted.
Thanks in advance,
Ed
$result = mysql_query("SELECT * FROM category")
or die(mysql_error());
echo "<select name='catid' id='catid'>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
// Print out the contents of each row into a table
echo "<option value='".$row['id']."'>";
echo $row['category'];
echo "</option>";
echo "\n";
This is fine for an upload form (where I've got it from) but not for an edit form. I need it to haev selected=selected by the option that matches my category id.
Just for reference the outputted html of the above is
<select name='catid' id='catid'><option value='1'>Cat1</option>
<option value='2'>Cat2</option>
<option value='3'>Cat3</option>
<option value='4'>Cat4</option>
</select>
My script is getting the recordid and calling it $id
It's then doing a sql select
$sql = "SELECT * FROM library WHERE id=$id";
I want it to grab the catid from this (catid being a field in the table) and then add selected=selected in the initial code I posted.
Thanks in advance,
Ed