?
Solved

SQL query in PHP script

Posted on 2011-05-09
5
Medium Priority
?
248 Views
Last Modified: 2012-06-27
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
Comment
Question by:Nura111
5 Comments
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 35725240
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
 
LVL 40

Expert Comment

by:mrjoltcola
ID: 35725267
Can you show your code? The line you gave is just building of the SQL, but not the execution of it.
0
 
LVL 35

Expert Comment

by:Norie
ID: 35725344
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
 
LVL 4

Expert Comment

by:Thankxx
ID: 35725381
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
 
LVL 40

Accepted Solution

by:
mrjoltcola earned 2000 total points
ID: 35729360
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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
MSSQL DB-maintenance also needs implementation of multiple activities. However, unprecedented errors can hamper the database management. In that case, deploying Stellar SQL Database Toolkit ensures fast and accurate database and backup repair as wel…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses
Course of the Month14 days, 9 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question