Hi,
I have a dropdown menu that is populated with entries from the MySQL database. What I want to do is when I 'EDIT' a product that the database populated dropdown menu has the 'value' that is stored in the database selected.
For example: A product called 'Dog Collar' is stored in the category 'Dogs'. So when I go to edit the Dog Collar product the Category dropdown menu has 'Dogs' option selected.
My current code for the dropdown menu is as follows:
// Dropdown Menu Populated with Categories
$sql = 'SELECT * FROM cateogories ORDER BY cat_name ASC';
//mysql query
$result = mysql_query($sql) or die('Query failed: ' . mysql_error());
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
$temp = array();
foreach ($line as $key=>$value){
$temp[$key] = $value;
}
$resultArray[] = $temp;
}
printf('<tr><td>Category:</td>');
echo'<td><select name="selCat" id="selCat" >'; foreach($resultArray as $row){ echo '<option label="'.$row['cat_id'].'"
value="'.$row['cat_id'].'">'.$row['cat_name'].'</option>';
}
echo '</select</td></tr>';
// END Dropdown Menu
Any help would be greatly appreciated!
Cheers 😃