Current location: Hot Scripts Forums » Programming Languages » PHP » SQL Query based on last 48 hours?


SQL Query based on last 48 hours?

Reply
  #1 (permalink)  
Old 05-07-08, 07:23 AM
philmckrackon philmckrackon is offline
New Member
 
Join Date: May 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
SQL Query based on last 48 hours?

Good day, I have a very simple mysql query that I would like to be based on time. I only want results for the query based on data from the prior 48 hours. After changing the query to what I believe is correct (with the help of others) I can never get passed a mysql fetch error. Any help would be aprreciated as I am stumped on this (so I thought) easy code.

Original SQL query that functions -
PHP Code:

$urls mysql_query("SELECT linkid,linkurl FROM adv_links ORDER by linkid ASC"); 

One of the many different new queries I have tried (dateline is the field with the date I need to reference)-
PHP Code:

$urls mysql_query("SELECT linkid,linkurl FROM adv_links ORDER by linkid ASC WHERE unix_timestamp() - dateline <= 3600*48"); 

And another query that does not work -
PHP Code:

$urls mysql_query("SELECT linkid,linkurl FROM adv_links ORDER by linkid ASC WHERE dateline > " . (TIMENOW - (24 60 60))); 

The fetch line that always errors out (with the remainder of the code)-
PHP Code:

while ($urlrow mysql_fetch_array($urls)) {

fwrite($file," ");
fwrite($file$urlrow[1]);
fwrite($file" | "); 
fwrite($file," ");
fwrite($file$urlrow[0]);
fwrite($file," \n");
}
fclose($file); 
?> 
And the error -
Quote:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/****/public_html/pagevisD.php on line 13
Thanks again,
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 05-07-08, 07:56 AM
Jay6390's Avatar
Jay6390 Jay6390 is offline
Code Master
 
Join Date: Apr 2007
Location: United Kingdom
Posts: 1,330
Thanks: 0
Thanked 0 Times in 0 Posts
SQL Code:
  1. SELECT `linkid`,`linkurl` FROM `adv_links` WHERE UNIX_TIMESTAMP() - UNIX_TIMESTAMP(`dateline`) < 172800
That should do it
__________________
Useful Tutorials
[ PHP Video-1-2-3 ] [ MySQL 1-2-3 ]
For any php function reference type

www.php.net/FunctionName
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
dynamic where section of sql query soloWebDev Script Requests 3 01-31-08 03:48 PM
ASP- SQL Server..Query help.... cancer10 Database 3 01-31-07 07:11 AM
Declared Functions skipper23 PHP 4 12-17-03 11:06 AM
index page not showing up skipper23 PHP 3 12-15-03 02:10 PM
change my field in this example sal21 ASP 3 07-14-03 03:49 AM


All times are GMT -5. The time now is 07:01 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.