Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

The Database Forum


You are currently viewing our The Database Forum as a guest. Please register to participate.
Login



Reply
Select rows by time interval
Old 08-22-2006, 06:00 PM Select rows by time interval
tomcat_fo's Avatar
Ultra Talker

Posts: 275
Trades: 0
Im making a FORM for my PHP website.... i want the things in the form to be visible in a preset time interval.

In the form users can chose how many days they want their post to be visible.... i also have current date in a set varible.

So i think i have the most important things.... curent date and number of days someone want their post to be visible.

How would the select look like for something like this in MySQL ... ?


Hope someone has an answer
tomcat_fo is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 08-22-2006, 11:59 PM Re: Select rows by time interval
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,898
Name: Keith Marshall
Location: Connecticut
Trades: 0
I think all you need is one field in the db that is filled with an expiration date. So you can use (just an example) the following to insert your new form post.

PHP Code:
// Insert into table_name auto increment for the id and the current time multiplied by the number of days user wants it to expire
$sql 'INSERT INTO table_name (id, expire) VALUES("", "' . ( time() + ((int)$_POST['expire'] * 86400) ) . '"'

Then when you are returning the posts that not yet have expired, just use this for example:

PHP Code:
// Select all from table_name where the exipation date is before current date
$sql 'SELECT * FROM table_name WHERE expire <= NOW()'
__________________

<mgraphic /> - I don't have a solution but I admire the problem.

Last edited by mgraphic; 08-23-2006 at 12:00 AM..
mgraphic is online now
Reply With Quote
View Public Profile
 
Old 08-23-2006, 10:34 AM Re: Select rows by time interval
tomcat_fo's Avatar
Ultra Talker

Posts: 275
Trades: 0
In your example... is $_POST['expire'] a date or a number of days ?


In my form i want users to be able to let their post be visible for MAX 30 days, so i have made a <select> wich contain numbers 1-30
tomcat_fo is offline
Reply With Quote
View Public Profile
 
Old 08-23-2006, 11:30 AM Re: Select rows by time interval
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,898
Name: Keith Marshall
Location: Connecticut
Trades: 0
Yes, its a whole number of days from now set to expire because it's being multiplied by 86400 (number of seconds in one day) added to the current time (also in seconds from the Epoch).

I messed up in the insert command, because you would need to format the time in a sql date format.

PHP Code:
// Insert into table_name auto increment for the id and the current time multiplied by the number of days user wants it to expire
$sql 'INSERT INTO table_name (id, expire) VALUES("", "' date('Y-m-d', ( time() + ((int)$_POST['expire'] * 86400) )) . '"'
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is online now
Reply With Quote
View Public Profile
 
Old 08-23-2006, 01:43 PM Re: Select rows by time interval
tomcat_fo's Avatar
Ultra Talker

Posts: 275
Trades: 0
Thanks a lot, i belive that must work.... just don't have time to try it right now - have got a lot of other loose ends in my website - had set the deadline by the end of this month (my own website, but want other things running next month, so hope to stick to the plan)
tomcat_fo is offline
Reply With Quote
View Public Profile
 
Old 08-25-2006, 04:39 PM Re: Select rows by time interval
tomcat_fo's Avatar
Ultra Talker

Posts: 275
Trades: 0
Now i'v looked at it againg, and i get a message saying:
Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /usr/home/web/web128130/kikarin/lysing1.php on line 136

my insert looks like this:
mysql_db_query("$datab", "INSERT INTO lysingar (navn, budstad, bygd, tlf, mail, dagar, pris, km, year, merki, motor, vekt, litur, brennievni, yvirskrift, tekstur, mynd, date, lysingbolkid, ip) VALUES ('$navn', '$budstad', '$bygd', '$tel', '$tmail', "' . date('Y-m-d', ( time() + ((int)$_POST['dagar'] * 86400) )) . '", '$pris', '$km', '$year', '$merki', '$motor', '$vekt', '$farva', '$brennievni', '$yvirskrift', '$stuttlysing', '".$fil."', '$cur_date', '$bolkid', '$ip')") or die('Ikki funni&eth;3');;
tomcat_fo is offline
Reply With Quote
View Public Profile
 
Old 08-26-2006, 06:56 AM Re: Select rows by time interval
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,519
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
it looks like your double & single quotes are the wrong way around here;

PHP Code:
tmail', "' date 
and here
PHP Code:
)) . '", 
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 08-27-2006, 12:02 PM Re: Select rows by time interval
tomcat_fo's Avatar
Ultra Talker

Posts: 275
Trades: 0
Now it inserts.... thanks !

BUT it insert the numer 2006 in the atribut no matter if i set the days(dagar) to 1 or 30 in my form...... and i belive 2006 must be the year 2006 that somehow ends up there.

The atribut type is set to integer.

Last edited by tomcat_fo; 08-28-2006 at 09:02 AM..
tomcat_fo is offline
Reply With Quote
View Public Profile
 
Old 08-28-2006, 09:02 AM Re: Select rows by time interval
tomcat_fo's Avatar
Ultra Talker

Posts: 275
Trades: 0
Hope someone knows what the problem is
tomcat_fo is offline
Reply With Quote
View Public Profile
 
Old 08-28-2006, 05:56 PM Re: Select rows by time interval
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,898
Name: Keith Marshall
Location: Connecticut
Trades: 0
Make sure the mysql field type is set to date instead of int.
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is online now
Reply With Quote
View Public Profile
 
Old 08-28-2006, 06:30 PM Re: Select rows by time interval
tomcat_fo's Avatar
Ultra Talker

Posts: 275
Trades: 0
Thanks that works perfectly now...
tomcat_fo is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Select rows by time interval
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.54195 seconds with 12 queries