• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 259
  • Last Modified:

SQL query in PHP script

Im trying to get the information from the database for the last 30 days .
when I'm performing the search directly in MySQL (phpmyadmin) its does retrieve results but in the php script from some reason its doesn't seem to return something

$query = "Select post_content from wp_posts WHERE post_date >= ADDDATE(curdate(), interval -30 day)";
0
Nura111
Asked:
Nura111
1 Solution
 
Ray PaseurCommented:
Maybe you can use PHP to generate the date.

$last_30 = date('c', strtotime('Today - 30 days'));
$query = "Select post_content from wp_posts WHERE post_date >= '$last_30' ";
0
 
mrjoltcolaCommented:
Can you show your code? The line you gave is just building of the SQL, but not the execution of it.
0
 
NorieVBA ExpertCommented:
The SQL looks fine, including the functions.

I think we might need to see the rest of the code.

Perhaps results are being returned but not in the way you expect, so the rest of the code isn't processing them properly
0
 
ThankxxCommented:
Hi,
You may try this:
$query = "SELECT post_content FROM wp_posts WHERE post_date BETWEEN SYSDATE() - INTERVAL 30 DAY AND SYSDATE();"
OR
$query = "SELECT post_content FROM wp_posts WHERE post_date BETWEEN DATE_SUB(NOW(), INTERVAL 30 DAY) AND NOW();"
OR
$query = "SELECT post_content FROM wp_posts WHERE post_date BETWEEN DATE_SUB(CURDATE(), INTERVAL 30 DAY) AND CURDATE();"

Thankxx


0
 
mrjoltcolaCommented:
Sure he can try all of those queries but his SQL is already valid, so until we see the rest of the code we won't see the problem.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now