显示名称而不是ID

时间:2013-02-23 07:43:06

标签: php html mysql

我开发了一个页面,显示表格中的所有卡车车牌号码以及每次点击它们进入此页面时的车牌号码并显示与该车牌号码相关的数据我的问题是显示卡车的名称只显示我点击的不同卡车的每一页上的第一个卡车牌号,但显示的数据是否正常我只是在显示正在显示的数据的卡车牌号时遇到问题

我通过这里<?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);
 ?>

1 个答案:

答案 0 :(得分: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";