Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-29-2012, 11:30 PM   PM User | #1
byrondallas
New Coder

 
Join Date: Jul 2011
Location: USA
Posts: 39
Thanks: 0
Thanked 1 Time in 1 Post
byrondallas is an unknown quantity at this point
Sqlite Help and total_count

I'm really a beginner when it comes to sqlite. I've only accomplished what I have now with allot of help from a friend. Let me first show you how I query my database and then I'll explain what I want to do. On my page it has the option to show a date selected and return the results (below).

PHP Code:
$db sqlite_open("load_db");
$q "SELECT *
      FROM serverload
      WHERE year='$year'
      AND month='$month'
      AND date='$date' "

And another option to show the entire month with a total count (below).

PHP Code:
$q "SELECT COUNT(*) as total_count 
      FROM serverload 
      WHERE year='$year'
      AND month='$month'"

What I'm wanting to do is return the most recent 7 days and get the total count. No matter what I've tried works. Can somebody show me how to do this?

Thank you!
byrondallas is offline   Reply With Quote
Old 07-30-2012, 08:45 AM   PM User | #2
redcrusher
New to the CF scene

 
Join Date: Jul 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
redcrusher is an unknown quantity at this point
Quote:
Originally Posted by byrondallas View Post
What I'm wanting to do is return the most recent 7 days and get the total count. No matter what I've tried works. Can somebody show me how to do this?
PHP Code:
SELECT count(*) AS 'blahblahblah'  FROM table 
PHP Code:
SELECT column FROM table ORDER BY somethingElse LIMIT 10 
hope that helps

Last edited by WA; 07-30-2012 at 06:43 PM..
redcrusher is offline   Reply With Quote
Old 07-30-2012, 01:03 PM   PM User | #3
byrondallas
New Coder

 
Join Date: Jul 2011
Location: USA
Posts: 39
Thanks: 0
Thanked 1 Time in 1 Post
byrondallas is an unknown quantity at this point
Thanks! This is what I ended up using and it seems to work pretty good. If anybody sees any syntax errors please let me know.

PHP Code:
$year date("Y");
$month date("M");
$now date("d");
$yesterday date("d"time() - 60 60 24);
$lastweek date("d"time() - 24 60 60);

$db sqlite_open("load_db");
$sql "SELECT count(*) as total_count 
      FROM  serverload
      WHERE year='$year'
      AND month='$month'
      AND date BETWEEN $lastweek AND $yesterday"
;

$results sqlite_query($db$sql);
$row sqlite_fetch_array($results);
$totalnum $row[total_count];
echo 
"$totalnum"
byrondallas is offline   Reply With Quote
Old 07-30-2012, 01:11 PM   PM User | #4
_Aerospace_Eng_
Supreme Master coder!


 
_Aerospace_Eng_'s Avatar
 
Join Date: Dec 2004
Location: In a place far, far away...
Posts: 19,292
Thanks: 2
Thanked 1,044 Times in 1,020 Posts
_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light
I would change
PHP Code:
$totalnum $row[total_count]; 
to
PHP Code:
$totalnum $row['total_count']; 
since 'total_count' is a string literal key in your results.
__________________
||||If you are getting paid to do a job, don't ask for help on it!||||
_Aerospace_Eng_ is offline   Reply With Quote
Old 07-31-2012, 01:25 AM   PM User | #5
byrondallas
New Coder

 
Join Date: Jul 2011
Location: USA
Posts: 39
Thanks: 0
Thanked 1 Time in 1 Post
byrondallas is an unknown quantity at this point
Done. Thank you!
byrondallas is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:24 PM.


Advertisement
Log in to turn off these ads.