What needs to be added to the SQL query in order to search for information from 5 or more tables? Now I am looking for information only from the tableEpson table. But there are a few more: such as tableSamsung , tableKyocera , etc. It is necessary to look for them too. What to add and how? enter image description here

 function search($words) { $words = strip_tags($words); if ($words === "") return false; $query_search = ""; $arraywords = explode(" ", $words); foreach ($arraywords as $key => $value) { if (isset($arraywords[$key - 1])) $query_search .= ' OR '; $query_search .= '`Model` LIKE "%'.$value.'%" OR `CartridgeNumber` LIKE "%'.$value.'%"'; } $query = "SELECT * FROM tableEpson, WHERE $query_search"; $mysqli = new mysqli ("localhost", "Имя пользователя", "Пороль", "Имя БД"); $result_set = $mysqli->query($query); $mysqli->close(); $i = 0; while ($row = $result_set->fetch_assoc()) { $results[$i] = $row; $i++; } return $results; } if (isset($_POST['bsearch'])) { $words = $_POST['words']; $results = search($words); print_r($results); } 
  • not databases but tables - L. Vadim
  • yes yes "Tables", thanks for the amendment. In a hurry wrote. - Metallistener
  • I think you should think about architecture. - Naumov
  • If you add a new supplier, for example SONY, then judging by the names of the tables, you will have to create for it a new tableSONY table. And this is not good. If you make one table with all the fields that you have in tableSamsung and add a field Provider - provider. Then requests can be easily written by changing the Where Provider = "samsung" field - Alexus
  • I have everything a little different with the table, you can look at the screen how my tables look and why I made my table for each brand. SCREEN loaded above. - Metallistener

2 answers 2

As an option for your picture:

  1. Printer models table models with fields
    • Id // 1
    • Name // CANON FC-108
    • Series // 128/200/206 ...
  2. Catridges

    • Id // 1
    • Name // FX-10
  3. Printer_catridge Printer cartridges (in case the printer supports multiple cartridges)

    • ModelID (link to models.ID)
    • CatridgeID (link to catridges.ID)
  4. Cartridge prices ( catridges_prices )
    • CatridgeID (link to catridge.ID)
    • price1
    • price2_3
    • ......
    • price11_13

The last table can be further improved.

  • Those. It is necessary to make only 4 separate tables from each other: 1) Table models 2) Table cartridges, etc. - Metallistener
  • do not tell me how to vote for an answer here so that your reputation goes for help - Metallistener
  • @ Dmitry How to vote for the answer - hover over the triangles with the number 0 - there will be a hint, and press what you think is necessary - Alexus
  • and the last question, if you please. For each brand, for example, Canon, the models are displayed in a loop in the table as in the screenshot, what should I do? list all Canon models separated by commas in the models table column model_series? Or use td tags instead of commas? - Metallistener
  • is already a design issue, so your preference is Alexus

If all tables are of the same format (with the same columns), you need to make UNION ALL between SELECT queries on each table, like:

 $myTables = array('tableEpson', 'tableSamsung'); $myQueries = array(); foreach ($myTables as $table) { $myQueries[] = "select * from $table where $query_search"; } $query = implode(' union all ', $myQueries);`