Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

[Php Sql] How to "Select" from two or multiple tables?

Discussion in 'Multiplayer' started by Ciava, Aug 17, 2020.

  1. Ciava

    Ciava

    Joined:
    Jun 1, 2018
    Posts:
    50
    Hello.
    In my "TestApp" I have a remote mySql database. From some tutorial I have a PHP script like this:

    Code (CSharp):
    1. <?php
    2. $servername = "sql.***.it";
    3. $username = "***";
    4. $password = "***!";
    5. $dbName = "***";
    6.  
    7. // Create connection
    8. $conn = new mysqli($servername, $username, $password, $dbName);
    9.  
    10. // Check connection
    11. if ($conn->connect_error) {
    12.     die("Connection failed: " . $conn->connect_error);
    13. }
    14. $conn->set_charset("utf8mb4"); // Impostiamo la codifica corretta
    15.  
    16.  
    17. $sql = "SELECT ID, Domanda, Esatta, Errata1, Errata2, Errata3, Immagine, Url_Audio, Url_Immagine FROM Table1"
    18.  
    19. $result = $conn->query($sql);
    20.  
    21. if ($result->num_rows > 0) {
    22.     // output data of each row
    23.     while($row = $result->fetch_assoc()) {
    24.         echo "ID".$row['ID'] .
    25.         "|Domanda" . $row["Domanda"] .
    26.         "|Esatta" . $row["Esatta"] .
    27.         "|Errata1" . $row["Errata1"] .
    28.         "|Errata2" . $row["Errata2"] .
    29.         "|Errata3" . $row["Errata3"] .
    30.         "|Immagine" . $row["Immagine"] .
    31.         "|Url_Audio" . $row["Url_Audio"] .
    32.         "|Url_Immagine" . $row["Url_Immagine"] .
    33.         ";";
    34.     }
    35. } else {
    36.     echo "0 results";
    37. }
    38. $conn->close();
    39.  
    40. ?>
    Now. I have other similar tables (same structure, different data). Is it possible to read from two (or more, maybe ALL) tables? Data is then stored in LISTS in unity.

    if I use this code:
    Code (CSharp):
    1. $sql = "SELECT ID, Domanda, Esatta, Errata1, Errata2, Errata3, Immagine, Url_Audio, Url_Immagine FROM Table1, Table2"
    It give me "0 results". Of course if I just type in Table1 or Table2 ... it works!

    Thank for your help!
     
  2. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,737