Jump to content

[SOLVED] Multiple where commands on a select.


cooldude832

Recommended Posts

I want to query my User contributions tables and return results like

Post in last day: 15

Post in last week: 20

Post in last month: 100

Post in last year: 10000

 

Can I do this via one query if my table is like

 

Posting

PostID

UserID

PostDate

Post

etc.

 

I don't know how to do the multiple limiting "wheres" on the selects.

 

can you show me an example

would I do something

<?php
$userid = "15";
$oneweek = date("Y-m-d G:i:s", strtotime("-7 Days"));
$q = "Select SUM(if(Post_Date >= '".$oneweek."')Posting_Table.Post_date) as `One_week` From `Posting_Table` Where Userid = '".$userid."'";
?>

 

I never done a mysql if

<?php
$q = "SELECT 
        SUM(IF(Post_date > NOW() - INTERVAL 1 DAY, 1, 0)) AS lastday ,
        SUM(IF(Post_date > NOW() - INTERVAL 7 DAY, 1, 0)) AS lastweek ,
        SUM(IF(Post_date > NOW() - INTERVAL 1 MONTH, 1, 0)) AS lastmonth ,
        SUM(IF(Post_date > NOW() - INTERVAL 1 YEAR, 1, 0)) AS lastyear
      FROM Posting_Table
      WHERE Userid = '$userid' ";  

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.