0

I have finally managed to get my code to return the first column from each one of two tables, but how do i change the code to return all the various column data from both tables and in order by an ID number. Here is my code

<?php
$mysqli = mysqli_connect("localhost", "name", "pass", "db");
// check connection
    if (mysqli_connect_errno()) {
      echo "Connect failed: " . mysqli_connect_errno(); exit();
    }

$query = "SELECT * FROM custrec;"; "SELECT * FROM contidr;";

$result = array();


/* execute multi query */
if ($mysqli->multi_query($query))
{
    do 
  {
      //store first result set
      if($result = $mysqli->store_result()) 
     {
         while( $rows = $result->fetch_row())
         {
               printf("<br/>%s<br/>", $rows[0]);
         }
             $result->free();
     }
        /* print divider */

        if($mysqli->more_results())
        {
            printf("-----------------<br/>");
        }
        else
        {
            echo '<br/>';
        }
} while($mysqli->more_results() && $mysqli->next_result());
}

/* close connection */
$mysqli->close();
?>
  • `$query = "SELECT * FROM custrec;"; "SELECT * FROM contidr;";` What's that? Try to write on your own instead of copy-pasting codes. – Aycan Yaşıt Oct 27 '13 at 07:05
  • Umm what's this? `$query = "SELECT * FROM custrec;"; "SELECT * FROM contidr;";` – Hanky Panky Oct 27 '13 at 07:05
  • @ Aycan I did not copy and paste anything ahole, I just followed advice that you lot dish out – user2042111 Oct 27 '13 at 07:22
  • I tried this that didint help.....$query = "SELECT `cid`, `Cust_type`, `no_chd`, `aPref`, `vetId`, `icin` FROM custrec"; $query = "SELECT `icin`, `id_type`, `first_name`, `last_name`, `add_li1`, `add_li2`, `town_city`, `state`, `postcode`,`email`, `ph_area_code`, `phone`, `mobile`, `cid` FROM contidr"; – user2042111 Oct 27 '13 at 07:40

1 Answers1

1

There is nothing wrong with the multi_query portion.

You have an error in the way you have assigned your two queries to $query.

Your:

$query = "SELECT * FROM custrec;"; "SELECT * FROM contidr;";

is like saying:

$query = "SELECT * FROM custrec;";
"SELECT * FROM contidr;";

The second intended query is not appended to $query.

Solutions are: One string (preferred):

$query = "SELECT * FROM custrec;SELECT * FROM contidr";

or two strings with concatenation:

$query = "SELECT * FROM custrec;"."SELECT * FROM contidr";
mickmackusa
  • 43,625
  • 12
  • 83
  • 136