Tell me, I deduce the values ​​in option from the option , the problem is that all the values ​​are output from the marka line, it turns out a lot of option with the same value in this case Toyota ... I tried to add the line marka_id to mysql and only write one value there, but empty option fields have appeared, it may somehow try to output a bunch of strings id + marka, only I don’t know how to implement it.

 <select class="filtr__select" id="idcat"> <option id="marka-avto">марка</option> <?php //Выводим категории и ее ID while ($row=mysql_fetch_assoc($result)) { $id = $row['id']; // иднтификатор $marka = $row['marka']; echo "<option value=\"$id\">$marka</option>"; } ?> </select> 
  • Show your result and what should happen, and preferably $result itself, the query itself to the database. - Manitikyl
  • In short, there is a database, in this database, 5 lines (id, marka, marka_id, model, url), I fill these lines with the database as follows: id: 1, marka: toyota, marka_id: toyota, model: camry, url: http / .. .. // It turns out that the option has the marka (toyota) value and I have these options as much as the goods, but I need the Toyota option to be one (there will be other values ​​for example honda). $ query = "select * from filtr_db"; $ result = mysql_query ($ query) or die (mysql_error ()); - ilyaaa521
  • Well, I know what will help you, but it’s not clear how you will use $id in option ? For example id : 1 , marka : toyota and id : 2 , marka : toyota , what are you going to do with this? - Manitikyl

1 answer 1

If you have 'marka' == 'marka_id' in the database 'marka' == 'marka_id' , then I have not thought up anything more logical:

The request can be done like this:

SELECT DISTINCT(marka) FROM filtr_db

and then in the echo "<option value=\"$marka\">$marka</option>"; loop echo "<option value=\"$marka\">$marka</option>";

$id = $row['id']; - delete, it makes no sense from him, because you get that 2 identical marks have different id

  • That doesn't work ... The page doesn't load at all with such a request - ilyaaa521
  • @ ilyaaa521 What does he write? Any errors, or not? - Manitikyl
  • I see one option so far, to remake the database to create a separate marka table, only I don’t know how to integrate marka with the model - ilyaaa521
  • There are no mistakes at all, a blank page .... - ilyaaa521
  • console error 500 GET - ilyaaa521