Solved

how to display dates from last six months via mysql and php

Posted on 2011-03-09
7
337 Views
Last Modified: 2012-05-11
i have a date event listing and id like to show only the last six months entrys , how do i do that please.

heres what i have but it seams not to work

thank you in advance any code or help you may provide
$sql2 = mysql_query("SELECT event_title,event_body,event_start,event_stop FROM `events2` WHERE `event_title` ".$search."AND event_start > DATE_SUB(NOW(), INTERVAL 6 MONTH) ORDER BY event_start desc");

Open in new window

0
Comment
Question by:Johnny
  • 4
  • 3
7 Comments
 
LVL 34

Accepted Solution

by:
Beverley Portlock earned 500 total points
ID: 35085420
On first inspection this bit

$search."AND

raises my suspicions. I don't know what's in $search but I would put a space in front of that AND

$sql2 = mysql_query("SELECT event_title,event_body,event_start,event_stop
                         FROM `events2`
                         WHERE `event_title` ".$search." AND
                                event_start > DATE_SUB(NOW(), INTERVAL 6 MONTH)
                         ORDER BY event_start desc
                    ");
0
 

Author Comment

by:Johnny
ID: 35085461
search is getting a pattern (top line) from the database to search for matched date entries from event title

fixed "and" space still no joy
//$search="LIKE \'%bible%acevic%\'";
//$search="LIKE '".$row['search_info']."'";
$search="LIKE '".$search."'";

$sql2 = mysql_query("SELECT event_title,event_body,event_start,event_stop FROM `events2` WHERE `event_title` ".$search." AND event_start > DATE_SUB(NOW(), INTERVAL 6 MONTH) ORDER BY event_start desc");

Open in new window

0
 
LVL 34

Expert Comment

by:Beverley Portlock
ID: 35085757
Change it like so and post back what it says

//$search="LIKE \'%bible%acevic%\'";
//$search="LIKE '".$row['search_info']."'";
$search="LIKE '".$search."'";

$sql2 = mysql_query("SELECT event_title,event_body,event_start,event_stop FROM `events2` WHERE `event_title` $search AND event_start > DATE_SUB(NOW(), INTERVAL 6 MONTH) ORDER BY event_start desc")
[b]or die( "Failed with " . mysql_error() );[/b]

Open in new window

0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

Author Comment

by:Johnny
ID: 35085813
i think i got it now, can really confirm but it looks like it changed the listing im testing. this shows all future listings and takes from current date and displays 6 months in the past

that is what i wanted.

and to note i always got info(no errors) just didnt get correct listing

thanks for the help bportlock would not of gotten it with out you, you made me look for mistakes, and re-look at how i was getting the data

im gonna accept your first answer, i hate that inspiration is not counted here, let alone the actual answer

$sql2 = mysql_query("SELECT event_title,event_body,event_start,event_stop FROM `events2` WHERE `event_title` ".$search." AND DATE_SUB(CURDATE(),INTERVAL 6 MONTH) <= event_start ORDER BY event_start desc");

Open in new window

0
 

Author Closing Comment

by:Johnny
ID: 35085823
thanks again
0
 

Author Comment

by:Johnny
ID: 35085830
i meant i cant really confirm, grr wish we could edit posts
0
 
LVL 34

Expert Comment

by:Beverley Portlock
ID: 35085857
Glad you're sorted
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Parts and Products table schema in mysql 6 43
phpmailer in WHILE loop - weird results 10 28
PHP warning 4 30
MySQL  on Tomcat 8 27
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

910 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

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now