0

我开发了一个页面,在表格中显示所有卡车车牌号,当您单击它们时,车牌号每个他们转到此页面并显示与该车牌号相关的数据我的问题是显示卡车的名称它只显示我单击的不同卡车的每一页上的第一个卡车车牌号,但是显示的数据正常工作我只是无法显示正在显示的数据的卡车车牌号

我在这里显示车牌号,<?php echo $row['truck_plate_no'];?>但它只显示第一个车牌号这是我的代码:

<?php require_once('Connections/connect.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
case "text":
  $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  break;    
case "long":
case "int":
  $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  break;
case "double":
  $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
  break;
case "date":
  $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  break;
case "defined":
  $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  break;
  }
  return $theValue;
}
}

 mysql_select_db($database_connect, $connect);
 $query_join = "SELECT * FROM tbl_delivery_details, tbl_truck WHERE tbl_truck.id_truck=tbl_delivery_details.tbl_truck_id_truck ORDER BY tbl_delivery_details.id_delivery_details";
 $join = mysql_query($query_join, $connect) or die(mysql_error());
 $row_join = mysql_fetch_assoc($join);
 $totalRows_join = mysql_num_rows($join);

   $id_truck = mysql_real_escape_string($_GET['id_truck']);



  $sql_PK = "SELECT * FROM tbl_delivery_details WHERE tbl_truck_id_truck = {$id_truck}";
  $PK = mysql_query($sql_PK, $connect);
  if ( mysql_error() ) {
   die ( mysql_error());
 }
  $row_PK = mysql_fetch_assoc($PK);

  $truck_id = $row_PK['tbl_truck_id_truck'];



 $truck_id = mysql_real_escape_string($truck_id);



 $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.id_truck = tbl_delivery_details.tbl_truck_id_truck
 ORDER BY tbl_truck.truck_plate_no"; 



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

 $sum = 0;
 $sum1 = 0;

 ?>



 <!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/x  html">
 <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"/>
  <link rel="shortcut icon" href="images/icon.ico">
 </head>

 <body>

 <div id="logo">
         <a href="home.php" title="QCC Corporation"><img src="images/logo_comp.jpg" width="245" height="105" alt="QCC Corporation"></a>
     </div>
     <div id="nav">
         <a href="form.php">Add-Transactions</a>
         <a href="truck.php">Truck</a>
         <a href="driver.php">Driver</a>
         <a href="customer.php">Customer</a>
         <a href="fuelsource.php">Fill-up-source</a>
         <a href="report.php">Reports</a>
     </div>
     <div id="border">
        <hr />
     </div>

 <div id="content"><table border="1" table align="center">
           <th>Date</th>
           <th>Route</th>
           <th>Destination</th>
           <th>Van No.</th>
           <th>Waybill No.</th>
           <th>Charge Invoice</th>
           <th>Revenue</th>
           <th>Strip/Stuff</th>


         </tr>

   <?php do { ?>
     <tr>

       <td><?php echo $row_PK['delivery_details_date']; ?></td>
       <td><?php echo $row_PK['delivery_details_route']; ?></td>
       <td><?php echo $row_PK['delivery_details_destination']; ?></td>
        <td><?php echo $row_PK['delivery_details_van_no']; ?></td>
        <td><?php echo $row_PK['delivery_details_waybill_no']; ?></td>
       <td><?php echo $row_PK['delivery_details_charge_invoice']; ?></td>
       <td><?php echo $row_PK['delivery_details_revenue']; ?></td>
       <td><?php echo $row_PK['delivery_details_strip_stuff']; ?></td>
       </tr>

             <?php $revenue = $row_PK['delivery_details_revenue'];
                    $sum += $revenue;
              ?>

              <?php $strip = $row_PK['delivery_details_strip_stuff'];
                    $sum1 += $strip;
              ?>
            <?php } while ($row_PK = mysql_fetch_assoc($PK)); ?>
        </table>
  </div>
 <div id="revenue">
     Total Revenue: <?php echo $sum;?>
 </div>
     <div id="strip">
     Total Stripping/Stuffing: <?php echo $sum1;?>
     </div>
     <div id="head">
      <?php echo $row['truck_plate_no'];?>
     </div>
  </body>
  <div id="footer">
         <br/><br/>Copyright © 2013 WFJCC. All rights reserved.
 </div>
 </html>
 <?php
 mysql_free_result($join);
 ?>
4

1 回答 1

0

在您的查询中

$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.id_truck = tbl_delivery_details.tbl_truck_id_truck
ORDER BY tbl_truck.truck_plate_no"; 

WHERE tbl_truck.id_truck = tbl_delivery_details.tbl_truck_id_truck 似乎不正确,因为您应该根据 $truck_id 进行操作,而不是导致显示第一个车牌号。

WHERE tbl_truck.id_truck = $truck_id

$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.id_truck = $truck_id
ORDER BY tbl_truck.truck_plate_no"; 
于 2013-02-23T08:40:12.233 回答