Avatar of David Schure
David Schure

asked on 

Adding a condition to a query

Trying to add a condition to this query...Not well versed in PDO
$sql = <<<QUERY
SELECT 
  `s`.`session_id` AS ID,
  DATE_FORMAT(
    `s`.`session_date`,
    "%W, %M, %d, %Y"
  ) AS `DATE`,
  TIME_FORMAT(
    CONCAT(`s`.`time_slot_id`, ":00:00"),
    "%h:%i %p"
  ) AS `TIME`,
  `s`.`session_type` AS `TYPE`,
  `t`.`therapist_name` AS `THERAPIST`,
  `sc`.`session_status` AS `STATUS` 
FROM
  tbl_session_client sc 
  LEFT JOIN tbl_session s 
    ON `s`.`session_id` = `sc`.`session_id` 
  LEFT JOIN `tbl_therapist` `t` 
    ON `t`.`therapist_id` = `s`.`therapist_id` 
WHERE `sc`.`client_id` = :client_id 
ORDER BY `session_date` DESC
QUERY;

Open in new window

The condition is:
AND tbl_session.session_status="Booked"
PHP

Avatar of undefined
Last Comment
Ryan Chong
Avatar of Daniel Pineault
Daniel Pineault

I'm not well versed in PDO either, but would it not simply be
$sql = <<<QUERY
SELECT 
  `s`.`session_id` AS ID,
  DATE_FORMAT(
    `s`.`session_date`,
    "%W, %M, %d, %Y"
  ) AS `DATE`,
  TIME_FORMAT(
    CONCAT(`s`.`time_slot_id`, ":00:00"),
    "%h:%i %p"
  ) AS `TIME`,
  `s`.`session_type` AS `TYPE`,
  `t`.`therapist_name` AS `THERAPIST`,
  `sc`.`session_status` AS `STATUS` 
FROM
  tbl_session_client sc 
  LEFT JOIN tbl_session s 
    ON `s`.`session_id` = `sc`.`session_id` 
  LEFT JOIN `tbl_therapist` `t` 
    ON `t`.`therapist_id` = `s`.`therapist_id` 
WHERE `sc`.`client_id` = :client_id 
  AND `s`.`session_status` = "Booked" 
ORDER BY `session_date` DESC
QUERY;

Open in new window


ASKER CERTIFIED SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
PHP
PHP

PHP is a widely-used server-side scripting language especially suited for web development, powering tens of millions of sites from Facebook to personal WordPress blogs. PHP is often paired with the MySQL relational database, but includes support for most other mainstream databases. By utilizing different Server APIs, PHP can work on many different web servers as a server-side scripting language.

125K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo