我想要显示所有的车辆维护历史,当用户点击注册号。但是,当用户点击注册号时,页面只显示最新的数据。例如,TAC 2123有5条维护记录,但当用户选择注册号时,它只显示最新记录的详细信息。如何才能显示所有TAC 2123的维护记录?
下面是用户选择注册号的代码:
<table width="250" cellspacing="1" cellpadding="1" border="1" align="center">
<tr>
<td>No</td>
<td>Registration No</td>
</tr>
<?php
$count = 0;
$db = mysql_connect('localhost','root')
or die ("unable to connect");
mysql_select_db('fyp',$db) or die ("able to select");
$sql="SELECT * FROM vehicle_record WHERE faculty ='City Campus'";
$result = mysql_query($sql) or die ("Query failed!");
while($row = mysql_fetch_array($result)){
$count = $count + 1;
?>
<tr>
<td><?php echo $count; ?></td>
<td><a href="man_his_details.php?regis=<?php echo $row['regno']; ?>"><?php echo $row['regno']; ?></a></td>
</tr>
<?php
}
mysql_close($db);
?>
</table>
and here's the code to list all the maintenance record based on the selected registration number:
<table width="990" cellspacing="1" cellpadding="1" border="1" align="center">
<tr>
<td>No</td>
<td>Maintenance Date</td>
<td>Maintenance Detail</td>
<td>Last Mileage</td>
<td>Next Change (Mileage)</td>
<td>Warranty</td>
<td>Cost</td>
<td>Driver Name</td>
</tr>
<?php
$count = 0;
if(isset($_GET['regis']))
$regno = $_GET['regis'];
elseif(isset($_POST['regis']))
$regno = $_POST['regis'];
else
$regno = "";
$db = mysql_connect('localhost','root')
or die ("unable to connect");
mysql_select_db('fyp',$db) or die ("able to select");
$sql_select = "SELECT * FROM maintenance WHERE regno ='".$regno."' ";
//. " WHERE `regno`='".($regno)."'";
//die($sql_select);
$result = mysql_query($sql_select) or die ("Query failed!");
$row = mysql_fetch_array($result);
extract($row);
//die($sql_select);
$count = $count + 1;
?>
<tr>
<td><?php echo $count; ?></td>
<td><?php echo $row['mdate']; ?></td>
<td><?php echo $row['man_detail']; ?></td>
<td><?php echo $row['last_mile']; ?></td>
<td><?php echo $row['next_mile']; ?></td>
<td><?php echo $row['warranty']; ?></td>
<td><?php echo $row['cost']; ?></td>
<td><?php echo $row['driver_name']; ?></td>
</tr>
<?php
//}
mysql_close($db);
?>plzzz帮我!
发布于 2010-02-25 11:57:52
您需要在获取和打印记录的逻辑周围放置一个while循环:
while ($row = mysql_fetch_array($result)) {
$count = $count + 1;
?>
<tr>
<td><?php echo $count; ?></td>
<td><?php echo $row['mdate']; ?></td>
<td><?php echo $row['man_detail']; ?></td>
<td><?php echo $row['last_mile']; ?></td>
<td><?php echo $row['next_mile']; ?></td>
<td><?php echo $row['warranty']; ?></td>
<td><?php echo $row['cost']; ?></td>
<td><?php echo $row['driver_name']; ?></td>
</tr>
<?php
} // end while
mysql_close($db);
?>https://stackoverflow.com/questions/2331488
复制相似问题