从3个表中获取数据时出现PHP错误

时间:2018-03-15 05:00:32

标签: php html mysql sql phpmyadmin

需要帮助... !! 请有人帮我解决这个问题。 试图从4个表中获取详细信息

prod table (prod_name)
customer (first_name, last_name, addr1, addr2, landmark, addr3, cust_contact)
order_details (qty, order_date)
cust_order (totalamt)

代码:

$sql = "SELECT order_date, prod_name, qty, totalamt, first_name, last_name, cust_contact, addr1, addr2, landmark, addr3  
FROM prod,order_details,cust_order 
WHERE prod.prod_id = order_details.prod_id and order_details.order_id = cust_order.order_id and cust_order.cust_id = customer.cust_id and prod_name='".$pname."'";   

$result1 = mysqli_query($conn,$sql);

while($row = mysqli_fetch_array($result1, MYSQLI_ASSOC))
{
    echo "<tr>";
    echo "<td>".date('j F, Y', strtotime($row['order_date']))."</td>";
    echo "<td>".$row['prod_name']."</td>";
    echo "<td>".$row['qty']."</td>";
    echo "<td>".$row['totalamt']."</td>";
    echo 
    "<td>".$row['first_name']." ".$row['last_name']."<br/>"
    .$row['cust_contact']."<br/> "
    .$row['addr1']."<br/>"
    .$row['addr2']."<br/>"
    .$row['landmark']."<br/>"
    .$row['addr3']."<br/>
    </td>";
    echo "</tr>";
}

输出:

警告:

  

mysqli_fetch_array()要求参数1为mysqli_result,在第*行的/storage/ssd1/351/3928351/public_html/pname1.php中给出布尔值

1 个答案:

答案 0 :(得分:0)

你的Where子句包含和。因此,即使一个条件不满足,它也不会返回数据。通过打印它是否返回值来逐个检查查询条件