我正在尝试从两个表中返回数据。我收到“未选择数据库”错误。我只是在学习,所以请放轻松你的常识。我以为我把数据库选在了最上面,我是在其他地方遗漏了什么,还是我又弄得一团糟!?前 6 个 td 来自第一个表 (custrec),其余来自表 (contidr) 这是代码
<?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>