1
<?php require_once('Connections/connect.php'); ?>
<?php
 $id_truck = mysql_real_escape_string($_GET['id_truck']);
 $sql_PK = "SELECT * FROM tbl_truck WHERE id_truck = '{$id_truck}'";
 $res_PK = mysql_query($sql_PK, $connect);
 $row_PK = mysql_fetch_assoc($res_PK);
 $truck_plate = $row_PK['truck_plate_no'];
 $truck_plate = mysql_real_escape_string($truck_plate);

 $sql = "SELECT tbl_truck.truck_plate_no, 
    tbl_delivery_details.delivery_details_route, 
    tbl_delivery_details.delivery_details_destination, 
    tbl_delivery_details.delivery_details_van_no, 
    tbl_delivery_details.delivery_details_waybill_no, 
    tbl_delivery_details.delivery_details_charge_invoice,
    tbl_delivery_details.delivery_details_revenue,
    tbl_delivery_details.delivery_details_strip_stuff,
    tbl_delivery_details.delivery_details_date
    FROM tbl_truck, tbl_delivery_details 
    WHERE tbl_truck.truck_plate_no = tbl_delivery_details.tbl_truck_id_truck 
    AND tbl_truck.truck_plate_no = '{$truck_plate}'";

$res = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_array($res);
?>

<!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 http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Truck Delivery</title>
<link rel="stylesheet" type="text/css" href="qcc.css"/>
</head>
<body>
<?php echo $row_PK['delivery_details_route'];?>
</body>
</html>

mysql_fetch_assoc() 期望参数 1 是资源,布尔值在第 9 行的 C:\xampp\htdocs\qcc\truckdelivery.php 中给出,没有选择数据库

我不知道我在哪里弄错了代码;此页面是我制作的充满车牌号的表格中的链接,我使用此代码将车牌号变成了链接。

href="truckdelivery.php?id_truck=<?php echo $row_truck['id_truck']?>"><?php echo    $row_truck['truck_plate_no'];
4

2 回答 2

2

在处理查询结果之前检查 MySQL 错误。您的查询很可能以某种方式出错,因此mysql_query()没有返回有效结果,因此mysql_fetch_assoc()失败。

// ...
$PK = mysql_query($sql_PK, $connect);
if ( mysql_error() ) {
  die ( mysql_error();
}
$row_PK = mysql_fetch_assoc($PK);
// ...

此外:mysql_x()函数已被弃用。请改用PDOMySQLi

于 2012-12-22T12:31:06.173 回答
1

您的connect.php文件可能缺少mysql_select_db()声明。检查那个。

于 2012-12-22T13:00:09.300 回答