1
我需要從指定的表中選擇數據,並從顯示的數據中選擇一個變量,然後用它從另一個表中選擇並顯示所選數據,但是當數據即從預訂表中選擇的是多隻顯示變量中的第一個數據,這裏是我的代碼:如何在php中循環
$res1=mysqli_query($bd,"select * from booked where datefrom between '$from' and '$to' or dateto>='$from' and dateto='$to'");
$num1=mysqli_num_rows($res1);
if($num1>0)
{
for($y=0;$y<$row1=mysqli_fetch_assoc($res1);$y++)
{
$res=mysqli_query($bd,"select * from rooms where capacity>='$newcap' and room_number!='".$row1['roomnumber']."'");
while($row=mysqli_fetch_assoc($res))
{
echo'<div class="col-lg-4 col-md-4 col-sm-12">';
echo'<div class="newsBox">
<div class="thumbnail">
<figure><img src="reservation/img/rooms/'.$row['img'].'" width="230" height="150"></figure>
<div class="caption maxheight2">
<div class="box_inner">
<div class="box">
<a class="title"><strong>'.$row['name'].'</strong></p>
<b>'.$row['description'].'</b>
<p>'.$row['price'].'</p>
</div>
<a class="btn btn-default" href="info_pay.php?roomnumber='.$row['room_number'].'&roomtype='.$row['name'].'&from='.$_POST['from'].'&adult='.$_POST['adult'].'&child='.$_POST['child'].'&to='.$_POST['to'].'&roomprice='.$row['price'].'"><span class="glyphicon glyphicon-plus">Select this Room</span></a>
</div>
</div>
</div>
</div>';
echo'</div>';
}
}
}
[你的腳本是在對SQL注入攻擊的風險。(http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) –
對不起IM只是一個初學者可以幫我用我的代碼? – user3425772
您應該解釋您希望代碼執行的操作,即粘貼的代碼無法實現。 – sunny