Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 05-04-2008, 09:38 PM
PhilMcKrackon PhilMcKrackon is offline
 
Join Date: Apr 2008
Posts: 47
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default SQL Query based on last 48 hours?

I have a PHP file that I run as a cron task every 24 hours. Can some one help with a tweak to the query to only select matches that have occurred between the time the query is executed and through 48 hours before?

PHP Code:
$urls mysql_query("SELECT linkid,linkurl FROM adv_links ORDER by linkid ASC");
while (
$urlrow mysql_fetch_array($urls)) {
fwrite($file," ");
fwrite($file$urlrow[1]);
fwrite($file" | "); 
fwrite($file," ");
fwrite($file$urlrow[0]);
fwrite($file," \n");

How would I change
Code:
$urls = mysql_query("SELECT linkid,linkurl FROM adv_links ORDER by linkid ASC");
to accomplish this?

Any help would be appreciated!

Thanks,
Reply With Quote
  #2  
Old 05-04-2008, 11:18 PM
MoT3rror MoT3rror is offline
 
Join Date: Mar 2007
Posts: 423
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Is there a time column in your table?
Reply With Quote
  #3  
Old 05-04-2008, 11:27 PM
PhilMcKrackon PhilMcKrackon is offline
 
Join Date: Apr 2008
Posts: 47
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Yes there is - its "dateline" and as an example under PHPMyAdmin the field looks like "1207498258" for a particular entry. I am unsure how to read that with the SQL query and translate that to what I need.

Thanks for the reply,
Reply With Quote
  #4  
Old 05-05-2008, 12:08 AM
MoT3rror MoT3rror is offline
 
Join Date: Mar 2007
Posts: 423
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

PHP Code:
$time  mktime(date('H'), date('i'), date('s'), date("m"), date('d')-2date('Y'));

$data $db->query_read("SELECT * FROM table WHERE timecolumn > '"date('Y-m-d H:i:s'$time) . "'"); 
Reply With Quote
  #5  
Old 05-05-2008, 12:26 AM
PhilMcKrackon PhilMcKrackon is offline
 
Join Date: Apr 2008
Posts: 47
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thank you very much for the help. I'll give it a try.
Reply With Quote
  #6  
Old 05-05-2008, 12:51 AM
Eikinskjaldi's Avatar
Eikinskjaldi Eikinskjaldi is offline
 
Join Date: Feb 2006
Location: Hell, never looked better
Posts: 572
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

More easily done within mysql

...where unix_timestamp() - timecolumn <= 3600*48
Reply With Quote
  #7  
Old 05-05-2008, 01:46 PM
PhilMcKrackon PhilMcKrackon is offline
 
Join Date: Apr 2008
Posts: 47
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

After many frustrating hours I'm still having a problem. I have tried multiple ways of writing the SQL query line but it still is not correct. I am using this code
PHP Code:
$time  mktime(date('H'), date('i'), date('s'), date("m"), date('d')-2date('Y'));
$urls mysql_query("SELECT linkid,linkurl FROM adv_links WHERE dateline > '"date('Y-m-d H:i:s'$time) . "' ORDER by linkid ASC"); 
But my query is still returning all results from the beginning, not just the last two days. The query does sort by the correct order though. Any help would again be appreciated.

Thanks,
Reply With Quote
  #8  
Old 05-06-2008, 10:43 AM
Marco van Herwaarden Marco van Herwaarden is offline
 
Join Date: Jul 2004
Posts: 25,415
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Try:
PHP Code:
$urls mysql_query("SELECT linkid,linkurl FROM adv_links ORDER by linkid ASC WHERE dateline > " . (TIMENOW - (24 60 60))); 
Reply With Quote
  #9  
Old 05-06-2008, 02:06 PM
PhilMcKrackon PhilMcKrackon is offline
 
Join Date: Apr 2008
Posts: 47
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Marco van Herwaarden View Post
Try:
PHP Code:
$urls mysql_query("SELECT linkid,linkurl FROM adv_links ORDER by linkid ASC WHERE dateline > " . (TIMENOW - (24 60 60))); 
Thanks for the help but that bit of code gives me the error
Quote:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/*****/public_html/pagevisD.php on line 19
on the line after the SQL query call. I edited the SQL cal that works and changed linkid,linkurl to linkid,linkurl,dateline - then added fwrite($file, $urlrow[2]); to the output file as a test (and the date shows up) so I know it's not the dateline table entry that is the problem.

Other thoughts?

--------------- Added [DATE]1210086427[/DATE] at [TIME]1210086427[/TIME] ---------------

Quote:
Originally Posted by Eikinskjaldi View Post
More easily done within mysql

...where unix_timestamp() - timecolumn <= 3600*48
Sorry I missed this post, could you elaborate?

Thanks,

--------------- Added [DATE]1210108992[/DATE] at [TIME]1210108992[/TIME] ---------------

PHP Code:
$urls mysql_query("SELECT linkid,linkurl FROM adv_links ORDER by linkid ASC WHERE unix_timestamp() - timecolumn <= 3600*48"); 
Eikinskjaldi, tried this as the query and I get the same PHP error as above -
Quote:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/*****/public_html/pagevisD.php on line 19
I have tried several variations of both syntaxes above and the error persists. I'll keep trying...
Reply With Quote
  #10  
Old 05-07-2008, 03:33 AM
Eikinskjaldi's Avatar
Eikinskjaldi Eikinskjaldi is offline
 
Join Date: Feb 2006
Location: Hell, never looked better
Posts: 572
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

"timecolumn" is whatever field in your database contains the dateline data

its kicking an error because you dont actually have a field called "timecolumn"


It looks like your field is called dateline, so the sql is

[sql]
SELECT linkid,linkurl FROM adv_links
ORDER by linkid ASC
WHERE unix_timestamp() - dateline <= 3600*48
[/sql]
Reply With Quote
Reply


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. The time now is 01:11 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04629 seconds
  • Memory Usage 2,273KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)bbcode_code
  • (6)bbcode_php
  • (4)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete