我有一个表格路线,其中保存了所有行程。然后,根据$_SESSION
值,我将行程表中的所有数据提取到复选框数组中。MySQL在查询2中查找结果query1
<?php
session_start();
require("aacfs.php");
echo"<div class='box' style='display:inline-block;' >
<table width='800'><tr><td>
<table width=100 align=left class='hovertable' style='display:inline-block;'><tr><th align=center bgcolor=silver><font face=consolas>Choose Itinerary</font></th></tr>
<tr>
<td></br>
<form method=post>";
$result=mysql_query("select * from itinerary where aircraft = '$_SESSION[rtyp]' group by location");
$y=mysql_affected_rows();
for($i=0;$i<$y;$i++)
{$row=mysql_fetch_array($result);
$pr=$row['icode'];
$n=$row['location'];
$l=$row['btime'];
echo"<table border=1 align=center width=250>
<tr><td width=15>
<input type='checkbox' value='$n -> $l'>
</td><td>$n</td><td width=5>$l</td></tr>
</table>";
}
?>
然后,我有另一张表,其中保存了以前选择的行程。我们称之为位置表。我想要选择那里的所有数据,在我以前的查询中找到它。如果找到,该复选框将被自动检查。
因此,例如我已经从行程表中的这些数据:
,然后我有从位置表中的这些数据:
从所述位置的值表格应该是检查。意思是Cebu - Bohol
和Bohol - Cebu
数值在复选框上应该是查。我只是不知道如何使用查询来做到这一点。请帮帮我。谢谢。
编辑:我可以做我想做什么使用这个代码,
$result=mysql_query("select * from itinerary where aircraft = '$_SESSION[rtyp]' group by location");
while($row=mysql_fetch_array($result))
{
$pr=$row['icode'];
$n=$row['location'];
$l=$row['btime'];
$res=mysql_query("select * from location where reservno = '$_SESSION[rno]'") or die(mysql_error());
while($row1=mysql_fetch_array($res))
{
$loc=$row1['location'];
if($n==$loc)
{
echo"<table border=1 align=center width=250>
<tr><td width=15>
<input type='checkbox' value='$n -> $l' checked='yes'>
</td><td>$n</td><td width=5>$l</td></tr>
</table>";
$t=$_POST['prod'];
}
elseif($n!=$loc)
{
echo"<table border=1 align=center width=250>
<tr><td width=15>
<input type='checkbox' value='$n -> $l'>
</td><td>$n</td><td width=5>$l</td></tr>
</table>";
$t=$_POST['prod'];
}
}
}
但是,
,你可以看到,它呼应了行程的两倍。我怎么能一次回复行程?谢谢!
谢谢回答,但'icode'不会在位置表存在。我使用“位置”(例如'宿雾 - 保和省)来比较它们。 'location'字段是唯一的。 – xjshiya 2013-02-27 11:51:03
@xjshiya好吧,只是改变了比较到'位置' – 2013-02-27 11:52:57
试过了,但它没有做我想要的。有没有像'如果query_result_location存在于query_result_itinerary然后','如果不存在然后'?我希望在PHP部分也有一些帮助。谢谢! – xjshiya 2013-02-27 11:56:49