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