我想从两个表中获取数据。 hall_booking表中的UID是外键,注册中的uid是主键。
<?php
$bid=$_REQUEST['book_id'];
$uid=$_REQUEST['id'];
echo $sel="select * from hall_booking INNER JOIN registration ON
hall_booking.uid=registration.uid WHERE hall_booking.booking_id=$bid AND
registration.uid=$uid";
$res=mysql_query($sel) or die(mysql_error());
$row=mysql_num_rows($res);
while($fet=mysql_fetch_array($res))
{?>
<center><form name="details" method="post" >
<table border="0" cellspacing="8px" id="table">
<tr><td>First Name : </td><td><?php echo $fet['first_name']; ?></td></tr>
<tr><td>Last Name : </td><td><?php echo $fet['last_name'];?></td></tr>
<tr><td>Address : </td><td><?php echo $fet['address'];?></td></tr>
<tr><td>Contact no : </td><td><?php echo $fet['mobile_no'];?></td></tr>
<tr><td>E-mail ID : </td><td><?php echo $fet['email_id'];?></td></tr>
<tr><td>Status : </td><td><?php echo $fet['purpose']; ?></td>
<tr><td colspan="2" style="font-size:12px"><center><a
href="show_plot_booking.php"> <<Back </a></center></td></tr>
</table>
</form></center>
<?php } ?>
答案 0 :(得分:0)
检查您的$bid
并且$uid
不为空
尝试引用您的查询var
$sel="select * from hall_booking INNER JOIN registration ON
hall_booking.uid=registration.uid WHERE hall_booking.booking_id='$bid' AND
registration.uid='$uid'";
也改为assoc
while($fet=mysql_fetch_assoc($res))
也最好使用count行数或查询返回行
$row=mysql_num_rows($res);
if($row > 0) {
// do your stuff
}
else {
echo 'echo no rows found';
}