tags:

views:

29

answers:

1

i want to show all the vehicle maintenance history when user click on the registration number. but, when user click on the registration number, the page only show the latest data. for example, TAC 2123 have 5 maintenance record, but when user select the registration number, it only show the detail of the latest record. how can make it show all the TAC 2123 maintenance record?

here's the code for user select the registration number:

<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 help me!!!

+1  A: 
p00ya
thanks pooya..your code very useful..but it seem there still contain small error..the latest record not listed..let say TAC 2123 have 3 maintenance record..it only list 2 record while the last record is missing...can u help me on this :-)
did you make sure to delete `$row = mysql_fetch_array($result);` before the while loop?
p00ya
yes!!success..thanks pooya..u r really great n clever..thank so much!!