Search code examples
phpsqlselectinner-joinecho

INNER JOIN is not working, i do not get errors


$result = mysqli_query($conn,"SELECT * FROM table1 INNER JOIN `table2`
ON `table1`.`id`=`table2`.`id`;");

while ($row = mysqli_fetch_array($result) ){
  echo 'name <textarea>'.$row["name"].'</textarea>';
}

on LAb (wampserver) its working i get information about "name", but on really website i not get infromation about "name" .


Solution

  • May some error occur but aren't displayed.

    First I suggest you to check the connection:

    $conn = mysqli_connect("$host", "$user "my_password", "$DBname");
    /* check connection */
    if (mysqli_connect_errno()) {
        printf("Connect failed: %s\n", mysqli_connect_error());
        exit();
    }
    

    If it works, check for query errors:

    if($result = mysqli_query($conn,"SELECT * FROM table1 INNER JOIN `table2`
    ON `table1`.`id`=`table2`.`id`;"))
    {
        while ($row = mysqli_fetch_array($result) ){
          echo 'name <textarea>'.$row["name"].'</textarea>';
        }
    }
    else echo($conn->error);
    

    Other possible causes may are:

    • ON clause

      it's true the condition:

      ON table1.id=table2.id

      or it should be something like this?

      `ON `table1`.`id`=`table2`.`rif_id`
      
    • no data to select in table1 or table2

      In the live database did you check if there are data to select? May happens to forget to insert data in the live database.

    Also, did you tried the query manually in PhpMyAdmin?