0

I want to order my events well configured, what im facing is,

i order my events if they are open for selling, i show them first, after those i show the ones which are open for reservation and which cannot be sold, but when people make reservation, i open my events for them for 3-4 days where only the ones who made reservation can buy that event,

what i want is simple, i want to show the event that they have made reservation and the event is open for selling for the ones only who made reservation; first in order, after that, the ones which are open for all, and than the ones which cant be bought because they are only for reservation

for instance, A is an event open for all, B is open for reservation, C can be bought by the ones only who made a reservation,

what my query returns is : A - B - C

what i want is : C - A - B

i tried to change the query but i know that i made a mistake there

here is my code :

try
{
$event_query = "SELECT * FROM `events` ORDER BY `reservation` ASC, `eventdate` ASC";
$event_query_check = $db->prepare($event_query);
$event_query_check->execute();
$ac = $db->query("SELECT FOUND_ROWS()")->fetchColumn();
while($fetch = $event_query_check->fetch (PDO::FETCH_ASSOC) ){ 

// fetching the info exc in here


try {
$q = "SELECT * FROM `event_reservation` WHERE `attendee_id` = :attendee_id AND `event_id` = :event_id";
$check_query = $db->prepare($q);
$check_query->bindParam(':attendee_id', $userid, PDO::PARAM_INT);
$check_query->bindParam(':event_id', $event_id, PDO::PARAM_INT);
$check_query->execute();
$n2 = $db->query("SELECT FOUND_ROWS()")->fetchColumn();
}
catch(PDOException $e) {
$log->logError($e." - ".basename(__FILE__));
}

// not working part of the code

 if($n2){
$event_query = "SELECT * FROM `members` ORDER BY `reservation_open_to_sell` DESC, `reservation` ASC, `eventdate` ASC";
}

// ends here

} // end of while
} // end of try
catch(PDOException $e) {
$log->logError($e." - ".basename(__FILE__));
}

Thank you

1
  • What are the values in reservation_open_to_sell column, for this query? Commented Nov 9, 2012 at 21:38

1 Answer 1

1

you can do something like this:

order by case when reservation='c' then 1 
              when reservation='a' then 2
              when reservation='b' then 3 end
Sign up to request clarification or add additional context in comments.

1 Comment

thank you for your answer, but i need to do that if someone has made a reservation, how will i configure that, not in the bottom, i need it in the top of the code block but i need to do that for all events thats why i use the while fetch exc part and then only i can do that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.