Solved

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

Posted on 2011-03-09
7
334 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Foreword In the years since this article was written, numerous hacking attacks have targeted password-protected web sites.  The storage of client passwords has become a subject of much discussion, some of it useful and some of it misguided.  Of cou…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
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.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

743 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

13 Experts available now in Live!

Get 1:1 Help Now