Hello, I have a question. Suppose there is a base with columns

An example of blocks (they contain the request code) and all blocks are separate from each other.

enter image description here

id - name - type - text

and a few queries to the database:

<?php require "подключение"; $sql = "SELECT name, id FROM таблица WHERE type='такой-то'"; $result = $conn->query($sql); if ($result->num_rows > 0) { while($row = $result->fetch_assoc()) { echo "".$row['id']."";}} else { echo "пусто"; } $conn->close(); ?> 

and such zaprov on the page about ten pieces ...

How can these queries be combined into one query ?

Here is an example of how the code looks on the page now (three blocks):

 блок1 <?php require "подключение"; $sql = "SELECT name, id FROM таблица WHERE type='1'"; $result = $conn->query($sql); if ($result->num_rows > 0) { while($row = $result->fetch_assoc()) { echo "".$row['id']."";}} else { echo "пусто"; } $conn->close(); ?> блок2 <?php require "подключение"; $sql = "SELECT name, id FROM таблица WHERE type='2'"; $result = $conn->query($sql); if ($result->num_rows > 0) { while($row = $result->fetch_assoc()) { echo "".$row['id']."";}} else { echo "пусто"; } $conn->close(); ?> блок3 <?php require "подключение"; $sql = "SELECT name, id FROM таблица WHERE type='3'"; $result = $conn->query($sql); if ($result->num_rows > 0) { while($row = $result->fetch_assoc()) { echo "".$row['id']."";}} else { echo "пусто"; } $conn->close(); ?> 
  • WHERE type in ('1','2','3') - splash58
  • Well, run a loop in which type like i++ and substitute it into the query. - Dan the Hat
  • @ Daniel option from splash58 isn't it? Just list the fields you need - DaemonHK
  • Each block is separated (added a picture) and in each block the information SELECT name is displayed, id FROM table WHERE type = 'type' (name and ah-di) just for a specific block ie in other words, “type” is the name of one block, and the WHERE type in ('1', '2', '3') variant outputs data only once - Daniel
  • one
    SELECT name, id, type FROM таблица WHERE type in ('1','2','3') . Next, using php, form three arrays (in the type column) and stuff the data into your blocks - ArchDemon

0