?
Solved

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

Posted on 2011-03-09
7
Medium Priority
?
344 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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 

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

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

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

In this blog post, we’ll look at how using thread_statistics can cause high memory usage.
In this article, we’ll look at how to deploy ProxySQL.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

741 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