Jump to content

Recommended Posts

I'm not sure if this problem is related to the query style or my JOIN. Tried LEFT JOIN and straight JOIN.

The following works fine.

$sql_statement = <<<END_OF_SQL

SELECT DISTINCT(`rr`.`GuestID`) AS `Guest ID`,
`rr`.`FromDate` AS `Check In Date`,
`rr`.`ToDate` AS `Check Out Date`,
`g`.`firstname` AS `First Name`,
`g`.`lastname` AS `Last Name`,
`g`.`email` AS `Email`,
`g`.`phone` AS `Phone`,
`g`.`address` AS `Address`,
`g`.`city` AS `City`,
`g`.`state` AS `State`,
`g`.`country` AS `Country`,
`g`.`zip` AS `Zip`,
`g`.`user_id` AS `User ID`
FROM `room_reservations` as `rr`
LEFT JOIN `guests` AS `g`
ON `g`.`user_id` = `rr`.`GuestID`

END_OF_SQL;

I however wish to add a date filter to this query and adding

WHERE `rr`.`FromDate`>=$specstart AND `rr`.`ToDate`<=$specend

doesn't work.

$sql_statement = <<<END_OF_SQL

SELECT DISTINCT(`rr`.`GuestID`) AS `Guest ID`,
`rr`.`FromDate` AS `Check In Date`,
`rr`.`ToDate` AS `Check Out Date`,
`g`.`firstname` AS `First Name`,
`g`.`lastname` AS `Last Name`,
`g`.`email` AS `Email`,
`g`.`phone` AS `Phone`,
`g`.`address` AS `Address`,
`g`.`city` AS `City`,
`g`.`state` AS `State`,
`g`.`country` AS `Country`,
`g`.`zip` AS `Zip`,
`g`.`user_id` AS `User ID`
FROM `room_reservations` as `rr`
LEFT JOIN `guests` AS `g`
ON `g`.`user_id` = `rr`.`GuestID`
WHERE `rr`.`FromDate`>=$specstart AND `rr`.`ToDate`<=$specend

END_OF_SQL;

 

I've alse tried using AND instead of WHERE, which doesn't give me the correct results.

 

Thank you for your time and help.

Link to comment
https://forums.phpfreaks.com/topic/271656-incorperating-php-to-excel-problem/
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.