Jump to content

Incorperating Php To Excel Problem


Drummin

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.