There are two tables in the database:

  1. _url with type field

  2. _splash with id and name fields

In the script, the data from the first table is displayed as: $url->type .

How to print name instead of $url->type if the type from the first table matches the id from the second, i.e. the data in the type field is taken from id ?

    2 answers 2

    as far as I understood $url -> type makes a query to the database and simply displays the result. Then you just need to change the function:

     $sql = "SELECT name FROM __splash JOIN __url ON __splash.id = __url.type;" //for MySQL $rs = mysqli_query($sql); foreach($row = mysqli_fetch_array($rs) as $key => $val) { echo $key . " :" . $val . "</br>"; } 

    if you need to change on a specific id then you need to transfer its value to $id in the function and finally add WHERE __url.name = {$id} to the request. Well, or just make requests to the __splash table instead of __url .

      In general, this is done through SQL, a view table is created that combines several tables into one (use join), and then output from this your table.

      Related Links: SQL Views SQL Joins

      • Why write something that is not in fact the answer, despite the fact that a detailed answer was given a few days ago? - Ordman
      • I wrote how to do it right. Related Links - w3schools.com/sql/sql_view.asp w3schools.com/sql/sql_join.asp - SeeNoMore
      • Try to write more detailed answers. Explain what is the basis of your statement? - Nicolas Chabanovsky