我正在尝试在php中运行一个简单的mysql查询,但是没有运行。它说B.ISBN等是未定义的索引。这是为什么 ? php无法识别mysql的AS(某些东西)吗?我已经过编辑,添加了文件的整个代码,对于任何误解,我们都很抱歉
<?php include 'dbconfig.php'; $Title = $_GET['Title'];?>
<?php header('Content-Type: text/html; charset=utf-8');?>
<!DOCTYPE HTML PUCLIC "-//W3C//DTDHTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<link rel="stylesheet" type="text/css" href="mytable.css">
<link rel="stylesheet" type="text/css" href="styles.css">
</HEAD>
<TABLE class="minimalistBlack">
<thead>
<tr>
<th> ISBN </th>
<th> Title </th>
<th> Number of Pages </th>
<th> Publisher Name </th>
<th> Copy Number </th>
<th> Shelf </th>
</tr>
</thead>
<?php
$conn= mysqli_connect("localhost","root","","library");
mysqli_set_charset($conn, "utf8");
if ($conn -> connect_error){
die("Conenction failed:". $conn->connect_error);
}
$sql="SELECT B.ISBN,B.Title,B.numpages,B.pubName,C.copyNr,C.shelf
FROM book AS B
INNER JOIN copies as C
ON B.ISBN=C.ISBN";
$result = $conn->query($sql);
if ($result->num_rows>0){
while($row= $result->fetch_assoc()){
echo "<tr>";
echo "<td>".$row['B.ISBN']."</td>";
echo "<td>".$row['B.Title']."</td>";
echo "<td>".$row['B.numpages']."</td>";
echo "<td>".$row['B.pubName']."</td>";
echo "<td>".$row['C.copyNr']."</td>";
echo "<td>".$row['C.shelf']."</td>";
}
echo "</TABLE>";
}
else { echo "0 result"; }
$conn->close();
?>
</TABLE>
</HTML>
答案 0 :(得分:1)
使用JOIN
:
SELECT B.ISBN,B.Title,B.numpages,B.pubName,C.copyNr,C.shelf
FROM book AS B
INNER JOIN copies as C
ON B.ISBN=C.ISBN
WHERE B.Title='$Title'";
答案 1 :(得分:0)
您可以使用此命名法命名表。
SELECT B.ISBN,B.Title,B.numpages,B.pubName FROM book B JOIN copies C WHERE B.ISBN=C.ISBN AND B.Title = '+$title;
答案 2 :(得分:0)
尝试以下查询:
SELECT B.ISBN,
B.Title,
B.numpages,
B.pubName,
C.copyNr,
C.shelf
FROM book as B
LEFT JOIN copies AS C ON B.ISBN=C.ISBN
WHERE B.Title = '”.$Title.”’”
答案 3 :(得分:0)
$sql="SELECT B.ISBN,B.Title,B.numpages,B.pubName,C.copyNr,C.shelf
FROM book AS B
INNER JOIN copies as C
ON B.ISBN=C.ISBN
WHERE B.Title = '".$Title."'";