Help plz! There are 2 tables in the database "teplo_db" and "category" in the first are products, in the second list of brands for products. PS The second table is needed to select a brand when making a product or to change when editing. When editing a product, I can’t do that - in the drop-down list, by default, there was a product brand, and not the first brand in the list. For example: I want to change the Samsung smartphone to Sony and by default the first brand from the list is displayed and not the real brand of the product.
- Attach the schema database, how are the tables related? - Sasha Borichevsky
- they are not connected, they are different tables (they are independent of each other). The main table in which all products are stored is "teplo_db" (name, brand, photo, etc.), auxiliary "category" there are brands and other information for the introduction of goods. - billov
|
1 answer
Must be added to the option tag
if ($result_category["id"] == $result["category_id"]) echo " selected"; to get it
<option value="1" selected> category_id must be replaced with a field that links to the category table.
I will add with the code:
do { echo '<option value="'.$result_category['id'].'"'; if ($result_category["brand"] == $result["brand"]) echo ' selected'; echo '>'.$result_category["id"].' '.$result_category["brand"].'</option>\r\n'; } - Thanks for the answer, but I still can not. If it is not difficult to write please part of the code that needs to be replaced. - billov
- Which field in the teplo_bd table refers to the brand ID from the category? - jurden
- The field "brand" is both tables. I substituted it on your advice. Most likely the problem is that I write lines of code in the wrong place. - billov
- Those. does teplo_bd store the brand name, not the id? - jurden
- Added to the answer code - jurden
|
