Forum Moderators: coopster

Message Too Old, No Replies

Extracting and displaying data

Echo based on date column and certain criteria

         

mvaz

3:13 pm on Jul 7, 2008 (gmt 0)

10+ Year Member



Hello
I have a database that is populated with various messages, wishes etc that my visitors input through a form on the web.

Most of the wishes are for days in the future and this is also populated through the form.

However, I was wondering if there was a way where only those wishes and messages for today and past days was extracted and displayed.

If I use “$result = mysql_query("SELECT * FROM {$table} WHERE $publish_Date =< today");” and did an echo, will the entire contents will be displayed or just those that are as I intend as below.

I do not want to display any messages that are for a future date even if a visitor changes the date on his/her computer.

I would be ever so grateful for any assistance and help provided.

cameraman

3:25 pm on Jul 7, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That should work, you just need to define 'today'. If you're using timestamps for the field then
$today = time();

I'm curious about the other two variables you're using in your statement, though - do the table name and field name change? If the table is wishes and the field is publish_date, for example, this is a little easier:
$result = mysql_query("SELECT * FROM wishes WHERE publish_Date =< $today");
since you don't have to define the variables $table and $publish_date.

mvaz

3:49 pm on Jul 7, 2008 (gmt 0)

10+ Year Member



Thanks for that Cameraman :) Yes, I think you got it spot on, the table is indeed wishes and publish_Date is the field for the date in mysql. I will try this and will come back to you if I get stuck midway. Cheers