Jump to content

Recommended Posts

Hello.

I'm quite happy ordering results normally... but what I'm trying to do now is order results based on multiple factors. - Let me explain.

 

I am writing a booking system to check the availability of days from the booking table, cross referenced with the rooms table. I loop through each day that has been requested to see whether each day is available or not. Then for each day that is available, it writes it into an array and for each day that is NOT available it writes a variable called "$not_available".

 

then I check if the variable "$not_available" is set... if it is, rather than providing a link to "book now" I provide a list of check boxes to select which dates to book...

 

Now... while that all works fine, the main issue for me is that I want the rooms that are available for the whole period to be ordered to the top, rather than just appear in the order they come from the database.

 

Is there any way of doing this?

here is some of my code:

<?php while($start_date!=$end_date_plus_one){
$qbook="SELECT COUNT(*) FROM `booking` WHERE ('$start_date' BETWEEN `start_date` AND
`end_date`) AND`room_id`='$room';";
#echo $qbook.'<BR>';

$sqlbook=@mysql_query($qbook);
$number=@mysql_result($sqlbook,0);
#echo $number.'<BR>';
if ($number>=1){
$number_of_days_booked++;
}
else{
// create an array for each day that has been noted.
$_SESSION['available_date'][$start_date]=$room;
}
$number_of_days_in_booking++;

#echo 'number of days booked: '.$number_of_days_booked.'<BR>';
#echo 'number of days in booking: '.$number_of_days_in_booking.'<BR>';
$start_date=date('Y-m-d',strtotime('+ 1 day', strtotime($start_date)));
}
if ($number_of_days_booked!=$number_of_days_in_booking){
?>
  <tr>
    <td class="calendar_header_weekend"><?php echo $r['name'];?>
        </div></td>
    <td class="calendar_bg" <?php if ($number_of_days_booked==0){ echo 'class="book_whole_time_slot"';} else {?> <?php }?>><?php 
if ($number_of_days_booked==0){?>
      All dates available. Book <?php echo $_SESSION['start_date'];?> to <?php echo $_SESSION['end_date'];?>.
      <?php }
else{?>Not all requested dates are available. Please select those you wish to book from the list below:<br /><?php 
	foreach ($_SESSION['available_date'] as $key => $value){
		echo date('D d M Y',strtotime($key));?>: <input name="<?php echo date($key);?>" type="checkbox" value="<?php echo date($key);?>" checked="checked" />
      <br />
      <?php
	}
}
session_unregister('available_date');
?></td>
    <td class="calendar_bg" <?php if ($number_of_days_booked==0){ echo 'class="book_whole_time_slot"';} else {?> <?php }?>><?php echo str_replace('_',' ',ucwords($type_of_room));?></td>
    <td class="calendar_bg" <?php if ($number_of_days_booked==0){ echo 'class="book_whole_time_slot"';} else {?> <?php }?>><div align="center">Book Now </div></td>
  </tr>
  <?php }
}?>

 

I hope I made myself clear. If you need more code, please ask, or take a look at: http://cornwalldevon.co.uk/accommodation_checker/14 and check the 22nd to the 30th of August 2008. Thanks a lot.

Link to comment
https://forums.phpfreaks.com/topic/120824-ordering-php-results/
Share on other sites

I hope I made myself clear. If you need more code, please ask, or take a look at: http://cornwalldevon.co.uk/accommodation_checker/14 and check the 22nd to the 30th of August 2008. Thanks a lot.

 

Doesnt do anything when these dates are checked and you submit the form.

 

Why arent you ordering the results returned by the database query i.e?

ORDER BY end_date DESC

Link to comment
https://forums.phpfreaks.com/topic/120824-ordering-php-results/#findComment-622929
Share on other sites

I'm not sure why it's not doing anything for you when you select those days but, i'm not ordering by the SQL result because that wouldn't do what i need it to do.

 

I want to select each room from the database, then for each record, test each day that has been submitted by the user, then if ALL days are okay, then display one result saying "book now" or if only some of the days are available, give them the option to select those only.

 

I want to order the "book now" results to the top, but because they are not SQL results, I don't know the best way to do it.

 

I'm sure that I can work something out, but thought you all might have an easy way to do it without tonnes of code (which would probably be my method).

 

Cheers,

Link to comment
https://forums.phpfreaks.com/topic/120824-ordering-php-results/#findComment-623156
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.