Jump to content

Show database entries by todays date plus 7 days


EarthDay
 Share

Go to solution Solved by EarthDay,

Recommended Posts

Hi there,

I am trying to show entries in my database that have todays date plus seven days.

My code is currently 

$stmt = $pdo->prepare('SELECT * FROM care_plan_review where reminder_date > ? order by id desc');

This does not work sadly.

Any thoughts?

Cheers, ED.

Edited by EarthDay
Link to comment
Share on other sites

9 minutes ago, Barand said:

Try

$stmt = $pdo->query("SELECT * FROM care_plan_review WHERE reminder_date > CURDATE() + INTERVAL 7 DAY");

Hi Barand,

Thank you for this.

I have updated my code and get the following error message;

Quote

Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens in /reminders.php:6 Stack trace: #0 /reminders.php(6): PDOStatement->execute() #1 {main} thrown in /reminders.php on line 6

Any ideas?

Cheers, ED.

Link to comment
Share on other sites

The full code is 

$now = date("Y-m-d h:i:sa");
$stmt = $pdo->prepare('SELECT * FROM care_plan_review where reminder_date > ? order by id desc');
$stmt->execute([$now]);
$allReview = $stmt->fetchAll(PDO::FETCH_ASSOC);

$now = date("Y-m-d h:i:sa");
$stmt = $pdo->prepare('SELECT * FROM care_plan_review where reminder_date > ? order by id desc');
$stmt->execute([$now]);
$allReview = $stmt->fetchAll(PDO::FETCH_ASSOC);

 

Link to comment
Share on other sites

  • Solution

Hi All,

Thank you all for your help on this :)

I have figured this out by using the below code

$stmt = $pdo->query("SELECT * FROM care_plan_review WHERE reminder_date between now() and now() + INTERVAL 7 DAY");

Cheers,

ED.

Link to comment
Share on other sites

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.

 Share

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