在search.php 中
<?php
$s=mysql_query("SELECT * FROM bus_detail where source_point='$_SESSION[source_point]' && destination_point='$_SESSION[destination]'");
while($row=mysql_fetch_array($s))
{
?>
<tr class="td_text">
<td>
<input name="bus_id" type="text" value="<?php echo $row['bus_id'];?>" style="border:0px; width:15px; text-align:left;" /></td>
<td>
<input name="bus_name" type="text" value="<?php echo $row['bus_name'];?>"/>
</td>
book.php
<?php
session_start();
require_once('config.php');
if (!isset($_SESSION)){
}
$bus_id=$_REQUEST['bus_id'];
$_SESSION['bus_id']=$bus_id;
?>
<div>
<?php
$s=mysql_query("SELECT * FROM bus_detail where bus_id='$_SESSION[bus_id]'");
while($row=mysql_fetch_array($s))
{ ?>
<?php echo $row['bus_name'];?>
<?php } ?>
</div>
当我搜索&只显示一个总线名称,我可以将其显示在book.phpdiv上。但当搜索后显示多个总线名称时,book.php页面的div上只显示最后一个总线名,我无法根据bus_id显示我的总线名称。。我认为在我的book.php页面中无法正确调用bus_id变量,会话可能会出现任何问题。因此,我在select语句中使用$bus_id
而不是会话进行检查,但出现了同样的问题。有什么帮助吗??提前感谢
您可以使用以下代码,
在搜索中.php
<?php
$s=mysql_query("SELECT * FROM bus_detail where source_point='$_SESSION[source_point]' && destination_point='$_SESSION[destination]'");
while($row=mysql_fetch_array($s))
{
?>
<tr class="td_text">
<td>
<input name="bus_id" type="text" value="<?php echo $row['bus_id'];?>" style="border:0px; width:15px; text-align:left;" /></td>
<td>
<input name="bus_name" type="text" value="<?php echo $row['bus_name'];?>"/>
</td>
<td><a href="book.php?bus_id=<?php echo $row['bus_id'];?>"><?php echo $row['bus_name'];?></a></td>
</tr>
<?php }?>
在书中.php
<?php
require_once('config.php');
if (!isset($_REQUEST['bus_id'])){
header('location:search.php');
}
$bus_id=$_REQUEST['bus_id'];
?>
<div>
<?php //display busid realted bus name
$s= mysql_query("SELECT * FROM bus_detail where bus_id='".mysql_real_escape_string($bus_id)."'");
$count =mysql_num_rows($s);
if($count>0){
while($row=mysql_fetch_array($s))
{
echo $row['bus_name'];
}
}else{
echo "Invalid Bus ID";
}
?>
</div>