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.

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

<?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' ";  

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.

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