A
A
arsenaljek2020-04-15 06:06:35
PHP
arsenaljek, 2020-04-15 06:06:35

How to correctly display data from mysql?

The task is to display a list of branches. At the moment, only two countries need a withdrawal, but it is better to do it for an infinite number.
Currently 2 requests are in use

SELECT * FROM filialy WHERE fed_okr_id IN(8) AND activity = 1  ORDER BY city
SELECT * FROM filialy WHERE fed_okr_id IN(1,2,3,4,5,6,7,9) AND NOT id = 29 AND activity = 1 ORDER BY city

And such a conclusion
<div class="mb-1">
        Россия:
        <?php 
        while ($row = mysqli_fetch_array($dealers_russia)) { ?>
          <a href="/filialy/<?=$row['link_filial']?>"><span class="badge badge-primary"><?=$row['city']?></span></a>
        <?php
        }
        ?>
      </div>
      <div class="mb-1">
        Кахастан:
        <?php 
        while ($row = mysqli_fetch_array($dealers_kz)) { ?>
          <a href="/filialy/<?=$row['link_filial']?>"><span class="badge badge-primary"><?=$row['city']?></span></a>
        <?php
        }
        ?>
      </div>


I changed the table structure and added linking fields, changed the query to
SELECT filialy.city, filialy.link_filial, city.name_city, city.countyId 
    FROM filialy 
    INNER JOIN city ON filialy.cityId = city.id_city
    WHERE filialy.activity = 1 
    ORDER BY filialy.city

But there was a problem with the output. how to competently display all branches related to a particular country without producing additional queries and cycles?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question