need to fix it the php code

PHP Code:

$link = mysqli_connect(“”,””,””,””); 
  if(!$link) { 
    die(‘Could not connect: ‘ . mysqli_error());
  }
 
  $statement = $link->prepare(“SELECT rooms FROM rooms WHERE id=(SELECT MAX(id) FROM rooms);”);  
  $statement->execute();  
  $statement->bind_result($bedCount);
  $statement->fetch(); 
  $statement->close();
  $statement = $link->prepare(“SELECT start_date, end_date FROM rooms WHERE rooms = ?;”); 
  $statement->bind_param(‘i’, $bedCount);  
  $statement->execute();  
  $statement->bind_result($startDate,$endDate);
  $dateList = array();
  $i = 0;
  while($statement->fetch()) { 
    $startDate = new DateTime($startDate);
    $endDate = new DateTime($endDate);
    while($startDate <= $endDate) {
      $result[$i][] = $startDate->format(‘Y-m-d’);
      $startDate->add(new DateInterval(‘P1D’));
    }
   $i++;    
  } 
  $statement->close();
  
  //
  //
  // Build all the variables we intend on using
  //
  //
  $mergedArray = array_reduce($result, “array_merge”, array());
  $arrayCount = array_count_values($mergedArray);
  switch($bedCount) {
    case 1:
      $brsoba = 1;
      break;
    case 2:
      $brsoba = 3;
      break;
    case 3:
      $brsoba = 1;
      break;
    case 4:
      $brsoba = 4;
      break;
    case 5:
      $brsoba = 1;
      break;
  }
  
  //
  //
  // Now build our page (I commented out the example items)
  //
  //
    
 
 echo ‘<h3>You choose ‘ . $bedCount . ‘-bed(s) and ‘ . (count($result) >  $brsoba ?  : “they are”) . ‘ in hotel ‘ . $brsoba . “.<BR />\n”.”<h3>”; 
  foreach($result as $inner) { 
   { 
    
    echo “<BR />\nRoom: ” . $bedCount .”-bed(s).” .”<BR />\n<BR />”; 
    
    foreach($inner as $date)   break; { 
       
       echo  ‘<font color=”#00BB3D”>’.”<BR />”. ($arrayCount[$date] <= $brsoba ? ($arrayCount[$date]  <= $brsoba? ”   Rooms available.</font><br><BR />\n” : ” <BR />\n”) : “<BR />\n”); 
       
      echo  ‘<font color=”red”>’.($arrayCount[$date] > $brsoba ? ($arrayCount[$date]  >= $brsoba? ”  No more rooms available.</font><br><BR />\n” : ” <BR />\n”) : “<BR />\n”); 
   break; 
    } 
  }  
 }
 
 
 
 
 
 
 
 
 
mysqli_close($link); 

start_date end_date rooms

2015-07-23 2015-07-29 1

2015-07-24 2015-07-25 1
those dates are in datebase should be message No […]

Original post by Pearl_9

Leave a Reply