1

i need to select data from table named booked from a given range of data and display data form a variable and then used it to select from another table and display the data that is selected but when the data that is selected from table booked is multiple only the first data is displayed in the variable here's my code:

$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>';
        }
     }
 }
Mubin
  • 4,325
  • 5
  • 33
  • 55

1 Answers1

-1

You may want to to try a different approach using heredoc as it is less prone to quoting errors, here's a complete example to loop a mysqli query using heredoc.

<?php

$con=mysqli_connect("localhost","my_user","my_password","my_db");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

$sql="select * from booked where  datefrom between '$from' and '$to' or dateto>='$from' and dateto='$to'";

if ($result=mysqli_query($con,$sql))
  {
  while ($row=mysqli_fetch_row($result))
    {
echo <<< LOL
        <div class="col-lg-4 col-md-4 col-sm-12">
                <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>
            </div>
LOL;

  // Free result set
  mysqli_free_result($result);
}

}
//close mysqli connection
mysqli_close($con);
?>
Pedro Lobito
  • 94,083
  • 31
  • 258
  • 268