簡體   English   中英

為什么PHP無法識別此查詢?

[英]Why doesn't php recognize this query?

我試圖在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>

使用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'";

您可以使用此命名法命名表。

SELECT B.ISBN,B.Title,B.numpages,B.pubName FROM book B JOIN copies C WHERE B.ISBN=C.ISBN AND B.Title = '+$title; 

請嘗試以下查詢:

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.”’”
$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."'";

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM