Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2011-03-09
7
Medium Priority
?
348 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 34

Accepted Solution

by:
Beverley Portlock earned 2000 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
Industry Leaders: 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!

 

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

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

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…
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

597 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