0

我正在用 PHP 编写汽车租赁脚本,我将所有汽车放在一个 SQL 表中,将所有汽车租赁放在另一个表中。如何在汽车下方显示所有租赁?

**Like this:**
bilar.reknr / Marke / Modell
starttid / stop tid
starttid / stop tid
starttid / stop tid

bilar.reknr / Marke / Modell
starttid / stop tid
starttid / stop tid

**EX**
ZOG-933 / BMW / 320
26.3.2013 / 27.3.2013
28.3.2013 / 29.3.2013
30.3.2013 / 31.3.2013

GOD-123 / MAZDA / 6
1.4.2013 / 2.4.2013
5.4.2013 / 6.4.2013

这是我现在的代码:

<?php
include 'connection.php';
$sqlquery = "SELECT * FROM bilar";
$sqlarray = mysql_query($sqlquery);
print "<table border='1'><tr>";
print "<td>Register nummer</td>";
print "<td>Marke</td>";
print "<td>Modell</td>";
print "<td>arsmodell</td>";
print "<td>personer</td>";
print "<td>fel</td>";
print "</tr>";
while ($row = mysql_fetch_array($sqlarray)) {
print "<tr style='font-weight:bold;'>";
//print "<td>" . $row['reknr'] . "</td>";
print "<td>" . $row['marke'] . "</td>";
print "<td>" . $row['modell'] . "</td>";
print "<td>" . $row['arsmodell'] . "</td>";
print "<td>" . $row['personer'] . "</td>";
print "<td>" . $row['fel'] . "</td>";
print "</tr>";
$iddd=$row['reknr'];
$sqlquery = "SELECT * FROM hyr";
$sqlarray = mysql_query($sqlquery);
while ($row = mysql_fetch_array($sqlarray)) {
if ($row['reknr']=$row['reknr1']){
print "<tr>";
print "<td>" . $row['startdat'] . "-" . $row['stopdat'] . "</td>";
print "<td>" . $row['starttid'] . "-" . $row['stoptid'] . "</td>";
print "</tr>";
}
}
}
print "</table>";   
mysql_close();

?>
4

2 回答 2

0

你可以试试这个

假设您具有以下表结构:-

  1. Car_table : car_id, car_name, car_color
  2. Rental_table:rental_id、car_id、rental_date

所以你的查询将是

$query = "Select Car_table.*,Rental_table.* from Car_table,Rental_table WHERE Car_table.car_id=Rental_table.car_id GROUP BY car_id"

然后休息我希望你知道该怎么做。希望这可以帮助

于 2013-03-26T09:53:32.413 回答
0
include 'connection.php';
$sqlarray = mysql_query("SELECT t1.*, t2.* FROM bilar t1 LEFT JOIN hyr t2 ON t1.reknr = t2.reknr1");
$arr = array();

print "<table border='1'><tr>";
print "<td>Register nummer</td>";
print "<td>Marke</td>";
print "<td>Modell</td>";
print "<td>arsmodell</td>";
print "<td>personer</td>";
print "<td>fel</td>";
print "</tr>";

$arr =array();
while ($row = mysql_fetch_array($sqlarray)) {

$arr[$row[0]]['marke']=$row[1];
    $arr[$row[0]]['modell']=$row[2];
    $arr[$row[0]]['arsmodell']=$row[3];
    $arr[$row[0]]['personer']=$row[4];
    $arr[$row[0]]['fel']=$row[5];
    $arr[$row[0]]['startdat'][]=$row[6];
    $arr[$row[0]]['stopdat'][]=$row[7];
}

foreach($arr as $reknr=>$row) {
print "<tr style='font-weight:bold;'>";
//print "<td>" . $reknr . "</td>";
print "<td>" . $row['marke'] . "</td>";
print "<td>" . $row['modell'] . "</td>";
print "<td>" . $row['arsmodell'] . "</td>";
print "<td>" . $row['personer'] . "</td>";
print "<td>" . $row['fel'] . "</td>";
print "</tr>";
for($i=0; $i <= count($row['startdat']) -1 ; $i++) {
print "<tr>";
print "<td>" . $row['startdat'][$i] . "-" . $row['stopdat'][$i] . "</td>";
print "</tr>";
}
}

print "</table>";
mysql_close();
于 2013-03-27T08:49:40.553 回答