removeDate and mySQL count

3 posts by 2 authors in: Forums > CMS Builder
Last Post: August 31, 2014   (RSS)

By shawn - August 20, 2014

Hi Guys

I am listing events which use the 'removeDate' field to expire the event. I'm also using <? echo mysql_count('events','');?> to show a count of the events.

Unfortunately, what is happening is that the count is still showing events that are expired because they aren't completely removed from the database.

Can you assist on this?

Thank you

Shawn

By gregThomas - August 21, 2014

Hey Shawn,

The mysql_count function can take a where statement as it's second value, and this will be used to filter the results. In your case it would be used like this:

<?php
  //Get the current time and date in SQL format
  $currentDate = date('Y-m-d H:i:s'); 
  echo mysql_count('events',"`removeDate` >= '$currentDate'");
?>

So the first value is the section you want to count the values from, and the second value is the where statement. 

The where statement will only return items which have a remove date greater or equal today.

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com

By shawn - August 31, 2014

Perfect! Thank you Greg :)