Unix Technical Forum

Displaying entry until specified date problem

This is a discussion on Displaying entry until specified date problem within the MySQL forums, part of the Database Server Software category; --> I have a mysql table (`news`) set up to hold news articles. It has 6 fields: `ID` (smallint - ...


Go Back   Unix Technical Forum > Database Server Software > MySQL

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 08:16 AM
JackM
 
Posts: n/a
Default Displaying entry until specified date problem

I have a mysql table (`news`) set up to hold news articles. It has 6
fields: `ID` (smallint - auto increment), `start` (date), `end` (date),
`headline` (varchar 255), `newsitem` (text), and `imp` (varchar 255 -
can be null). I want to get the headlines pulled from the table and
displayed on a page. I want them to display in ascending order by end
date and sub-ordered by the imp field until the date after the end date.
The imp field is used to push items that are farther off than the 8
selected to the top of the list for extra exposure.

Example: headline of "Free coffee Sept 28" carries an end date of
2006-09-28. I want that to stop displaying when today's date turns to
2006-09-29.

I can get the headline to display on the page properly but I seem to
have a mistake somewhere in getting it to stop displaying as of the
29th. The code I'm using is:

<?
mysql_connect("$dbhost","$dbuser","$dbpass"); //(host, username, password)
mysql_select_db("$dbase") or die("Unable to select database"); //select
database

$now = date("Y-m-d"); //today's date

$query = "SELECT * FROM `news` WHERE ($now < `end`) ORDER BY `imp`,`end`
LIMIT 8";

$result = mysql_query($query) or die(mysql_error());

//and then process the results.
?>

But the item that should have ceased being displayed on the 29th is
still displaying. What do I need to do to correct this?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-28-2008, 08:16 AM
strawberry
 
Posts: n/a
Default Re: Displaying entry until specified date problem


JackM wrote:
> I have a mysql table (`news`) set up to hold news articles. It has 6
> fields: `ID` (smallint - auto increment), `start` (date), `end` (date),
> `headline` (varchar 255), `newsitem` (text), and `imp` (varchar 255 -
> can be null). I want to get the headlines pulled from the table and
> displayed on a page. I want them to display in ascending order by end
> date and sub-ordered by the imp field until the date after the end date.
> The imp field is used to push items that are farther off than the 8
> selected to the top of the list for extra exposure.
>
> Example: headline of "Free coffee Sept 28" carries an end date of
> 2006-09-28. I want that to stop displaying when today's date turns to
> 2006-09-29.
>
> I can get the headline to display on the page properly but I seem to
> have a mistake somewhere in getting it to stop displaying as of the
> 29th. The code I'm using is:
>
> <?
> mysql_connect("$dbhost","$dbuser","$dbpass"); //(host, username, password)
> mysql_select_db("$dbase") or die("Unable to select database"); //select
> database
>
> $now = date("Y-m-d"); //today's date
>
> $query = "SELECT * FROM `news` WHERE ($now < `end`) ORDER BY `imp`,`end`
> LIMIT 8";
>
> $result = mysql_query($query) or die(mysql_error());
>
> //and then process the results.
> ?>
>
> But the item that should have ceased being displayed on the 29th is
> still displaying. What do I need to do to correct this?


Hmm, you know MySQL knows when now is. Try this:

$query = "SELECT * FROM `news` WHERE (now() < `end`) ORDER BY
`imp`,`end`
LIMIT 8";

Otherwise maybe try sticking $now into inverted commas:
> $now = "'".date("Y-m-d")."'"; //today's date


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-28-2008, 08:16 AM
JackM
 
Posts: n/a
Default Re: Displaying entry until specified date problem

strawberry wrote:

>>Example: headline of "Free coffee Sept 28" carries an end date of
>>2006-09-28. I want that to stop displaying when today's date turns to
>>2006-09-29.
>>
>>I can get the headline to display on the page properly but I seem to
>>have a mistake somewhere in getting it to stop displaying as of the
>>29th. The code I'm using is:
>>
>>$now = date("Y-m-d"); //today's date
>>
>>$query = "SELECT * FROM `news` WHERE ($now < `end`) ORDER BY `imp`,`end`
>>LIMIT 8";
>>?>


>
>
> Hmm, you know MySQL knows when now is. Try this:
>
> $query = "SELECT * FROM `news` WHERE (now() < `end`) ORDER BY
> `imp`,`end`
> LIMIT 8";


Well, duh! It never even occured to me that mysql knew when now is.
<slaps forehead> I'm so used to doing $now = mktime(); php statements
that I just carried it over to the mysql syntax. Thanks for putting me
straight on this. Your solution works perfectly and a lesson has been
learned.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 10:09 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com