daithi Posted May 20, 2003 Posted May 20, 2003 hi all, i need a page for updating products (outside of admin) all is working fine except for the categories drop down i use on the page, current code is: (taken from productadder.php) // category drop down $sql3 = mysql_query("SELECT categories_id, categories_name FROM categories_description ORDER BY categories_name"); $categorize = mysql_fetch_array($sql3); // category area in form <tr> <td><label for="categories_id_form">Category</td> <td> <select name="categories_id_form"> <?php if(mysql_num_rows($sql3)) { while($row = mysql_fetch_row($sql3)) { print("<option value="$row[0]">$row[1]</option>"); } } ?> </select> The proplem with this is that the category dropdown always has the first category selected, and if i forget to update this the product goes into the wrong category. Can anyone tell me how to get the category dropdown to have the current category that the product is in selected??? i have tried copying code from various other pages but am having no luck...any help would be greaty appreciated..thanks.
shagymoe Posted May 20, 2003 Posted May 20, 2003 I ran the select on my sample database and I would think that you would want to use "SELECT DISTINCT" so that you didn't get a bunch of repeats, but I didn't ponder that too long...maybe I'm wrong. For the drop down, how about something like this: if(mysql_num_rows($sql3)) { while($row = mysql_fetch_row($sql3)) { if ( $row[0] == VARIABLE_THAT_HOLDS_THE_CURRENT_CATEGORY ) { print("<option selected value="$row[0]">$row[1]</option>"); } else { print("<option value="$row[0]">$row[1]</option>"); } } I don't know what "VARIABLE_THAT_HOLDS_THE_CURRENT_CATEGORY" should be. I also don't know where you got the file "productadder.php" so its a little hard to locate a place where you might be able to pull that variable from. Matt
daithi Posted May 20, 2003 Author Posted May 20, 2003 For the drop down, how about something like this: if(mysql_num_rows($sql3)) { while($row = mysql_fetch_row($sql3)) { if ( $row[0] == VARIABLE_THAT_HOLDS_THE_CURRENT_CATEGORY ) { print("<option selected value="$row[0]">$row[1]</option>"); } else { print("<option value="$row[0]">$row[1]</option>"); } } Matt works a treat! thank you!
daithi Posted July 14, 2003 Author Posted July 14, 2003 has anyone any ideas on this? the site has now gone live at http://propertyireland.net/sales/default.php[/url] but i need to fix the drop down menu for when a user wants to submit an item.
Recommended Posts
Archived
This topic is now archived and is closed to further replies.