我正在尝试加入2个表并根据id更新表。使用外键连接2个表。 Id对于每一行都是唯一的。
这是桌面设计 表1
ID | routeno |名称| PHNO
表2
ID | routeno |拾取|时间|
我正在尝试基于routeno加入table1和table2。并根据id编辑表2。在我的代码中,如果table2中有3条记录,其routeno为1,则只有最后一条记录被编辑,其他记录不会被编辑。代码怎么了?
<?php
$result = mysql_query("select b.routeno, r.pickup,r.pickuptime,r.dropback,r.rate from routedetails AS r INNER JOIN busroute AS b ON b.routeno = r.routeno AND b.routeno = '$routeno' ");
if (mysql_num_rows($result) == 0) { echo "<h3 style=color:#0000cc;text-align:center;>No Routes Yet..!</h3>"; } else { ?>
<table cellpadding="10px" cellspacing="5" width="1200px" style="line-height:25px;font-size:1em;font-family:calibri" border="1" align="center">
<tr>
<td style="color:#1980bb;font-weight:bold;font-size:15px; width:250px;">Pick Up</td>
<td style="color:#1980bb;font-weight:bold;font-size:15px;width:250px;">Pick Up Time</td>
<td style="color:#1980bb;font-weight:bold;font-size:15px;width:250px;">Drop Up Time</td>
<td style="color:#1980bb;font-weight:bold;font-size:15px;width:250px;">Rate</td>
</tr></table>
<?php
if(isset($_POST['submit']))
{
$id=$_POST['id'];
$pickup=$_POST['pickup'];
$pickuptime=$_POST['pickuptime'];
$dropback=$_POST['dropback'];
$rate=$_POST['rate'];
$query3=mysql_query("update routedetails set id='$id', pickup='$pickup',pickuptime='$pickuptime',dropback='$dropback',rate='$rate' where id='$id'");
if($query3)
{
echo "<script>window.open('editroute.php?id='.$id.','_self')</script>";
}
}
$query2=mysql_query("select r.id,b.routeno,r.pickup,r.pickuptime,r.dropback,r.rate from routedetails AS r INNER JOIN busroute AS b ON b.routeno = r.routeno AND b.routeno = '$routeno' " );
while ($r1 = mysql_fetch_assoc($query2)) {
?>
</div>
<table>
<tr>
<td><input type="text" name="id" value="<?php echo $r1['id'] ?>"/></td>
<td><input type="text" name="pickup" value="<?php echo $r1['pickup'] ?>"/></td>
<td><input type="text" name="pickuptime" value="<?php echo $r1['pickuptime']?>"/></td>
<td><input type="text" name="dropback" value="<?php echo $r1['dropback'] ?>"/></td>
<td><input type="text" name="rate" value="<?php echo $r1['rate'] ?>"/></td>
</tr>
</table>
<?php } ?>
<?php }}
?>
<input type="submit" value="Edit"name="submit" class="nextbutton1">
</form>
</td>
</tr>
</table>