Solved

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

Posted on 2011-03-09
7
340 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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
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…
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 …

806 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