I am trying to return data from two tables. I am getting a No database selected error. I am only learning so go easy on me your common sense. I thought I had the database selected up top, am I missing something some where else or have i just made another mess!? The first 6 td's are from the first table (custrec), the rest from table (contidr) Here's the code
<?php
//connect to database
$mysqli = new mysqli('localhost', 'name', 'pass', 'Org_db');
// check connection
if (mysqli_connect_errno()) {
echo "Connect failed: " . mysqli_connect_errno(); exit();
}
$result = mysql_query("SELECT * FROM `custrec`
FULL OUTER JOIN `contidr` ON contidr.cid = custrec.`cid` WHERE custrec.`cid` = `1`");
if($result === FALSE) {
die(mysql_error()); // error handling
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8">
<title>Get queries - multiple Customer and contact details</title>
</head>
<body>
<table width="80%" border="1px">
<tr>
<th scope="col">Customer ID</th>
<th scope="col">Customer type</th>
<th scope="col">Number of Children</th>
<th scope="col">Animal Preference</th>
<th scope="col">Vet ID</th>
<th scope="col">Individual Contact ID Number</th>
<th scope="col">First Name</th>
<th scope="col">Last Name</th>
<th scope="col">Address L1</th>
<th scope="col">Address L2</th>
<th scope="col">Town/City</th>
<th scope="col">State</th>
<th scope="col">Postcode</th>
<th scope="col">Email</th>
<th scope="col">Postcode</th>
</tr>
<?php
while ($row = mysql_fetch_array($result)) {
?>
<tr>
<td><? echo $row["$cid"]; ?></td>
<td><? echo $row["$cust_type"]; ?></td>
<td><? echo $row["$no_chd"]; ?></td>
<td><? echo $row["$aPref"]; ?></td>
<td><? echo $row["$vetId"]; ?></td>
<td><? echo $row["$icin"]; ?></td>
<td><? echo $row["$id_type"]; ?></td>
<td><? echo $row["$first_name"]; ?></td>
<td><? echo $row["$last_name"]; ?></td>
<td><? echo $row["$add_li1"]; ?></td>
<td><? echo $row["$add_li2"]; ?></td>
<td><? echo $row["$town_city"]; ?></td>
<td><? echo $row["$state"]; ?></td>
<td><? echo $row["$postcode"]; ?></td>
<td><? echo $row["$email"]; ?></td>
<td><? echo $row["$ph_area_code"]; ?></td>
<td><? echo $row["$phone"]; ?></td>
<td><? echo $row["$mobile"]; ?></td>
</tr>
<?php }
/* close connection */
$mysqli->close();
?>
</table>
</body>
</html>
As it was noted in comments, you are mixing mysql and mysqli. And this is your problem.
For mysqli you already selected database but later you are using mysql functions, which causes the error. You have to use only mysqli functions.