Hi:
My name is Ken Cooper. I have a poll on my page. http://www.coopercentral.org -- Each week I have a poll. If you goto -- http://www.coopercentral.org/poll/pollarchive.php, there is a list of polls. I enter a date each poll too. What I want to do is, say I enter a new poll early a head of time, I don't want it to display in the polls list until another poll comes after it. Do you get what I mean anyone? Thanks for your help, I promise, LAST ONE!!! Thanks again!!!
Ken Cooper
Sorry, Last Question, PROMISE!! - Selecting Stuff database
Moderators: egami, macek, gesf
build you're query so that it doesn't select polls that are to start in the future for pages that are to be displayed by users.
that way you won't have to skip those when viewing them.
you can also check the date when actually printing them on you're page, if the date is in the future, the poll is not active yet and it shouldn't be displayed.
Greetz Daan
that way you won't have to skip those when viewing them.
you can also check the date when actually printing them on you're page, if the date is in the future, the poll is not active yet and it shouldn't be displayed.
Greetz Daan
-
- New php-forum User
- Posts: 40
- Joined: Fri Aug 09, 2002 11:53 am
- Location: Rochester, NY
- Contact:
Thanks a lot, the thing you said, that is what I want. I don't want to display them until the date is active. Could you possibly show me an example of SELECT code. I'm just learning. I'll fill in the other code. Thanks a lot!!
Ken Cooper
Ken Cooper
Thanks for your help!
somebody correct me if this is wrong.
dates are stored in the database as a unix-timestamp, you know, those weird numbers that look like a stardate
(example: "1022757069")
that number increases with time.
you can simply compare that number to another number to see wich one is greater or later in time.
the function "time()" returns a timestamp for the current time (servertime).
so that would make the query look like:
please note that the "time()" function also contains the hours, minutes and seconds....
Greetz Daan
dates are stored in the database as a unix-timestamp, you know, those weird numbers that look like a stardate

that number increases with time.
you can simply compare that number to another number to see wich one is greater or later in time.
the function "time()" returns a timestamp for the current time (servertime).
so that would make the query look like:
Code: Select all
$query = 'select `field_stuff` from `table_stuff` where `date_field` < "' . time() . '" ';
please note that the "time()" function also contains the hours, minutes and seconds....
Greetz Daan
-
- New php-forum User
- Posts: 40
- Joined: Fri Aug 09, 2002 11:53 am
- Location: Rochester, NY
- Contact:
Thanks a lot, I really appreciate it. I was thinking, I bet I could use the
now() function as well. It gets the Servers date. That might work too. Thanks a lot, I really appreciate it.
Ken Cooper
now() function as well. It gets the Servers date. That might work too. Thanks a lot, I really appreciate it.
Ken Cooper
Thanks for your help!
dvdbinternet wrote:somebody correct me if this is wrong...
please note that the "time()" function also contains the hours, minutes and seconds....
Greetz Daan
Nope, that's wrong. The unix timestamp (or time() function) is simply the number of seconds that has passed since Jan 1st 1970 I believe. Either way, it's just the number of seconds, and it's from this that the current time can be determined.
MySQL is perfectly capable of storing dates and times in their proper formats and performing calculations upon them in said format. There is a whole chapter on Date and Time functions with examples of how to use it, you can see it here
Kenneth, to skip a row codewise all you need to do is put an $i++ code in your loop (with $i = 0 on the outside to start it), and just add before anything else if ($i == 0) continue; and this will skip the loop and start again with the second row)
-
- New php-forum User
- Posts: 40
- Joined: Fri Aug 09, 2002 11:53 am
- Location: Rochester, NY
- Contact:
It's ok, I got what I wanted. What I did was, something like:
SELECT question FROM polls WHERE date_field < now()
And it works. If I create 10 polls ahead of time, I don't want them to show. But they show when another poll is active, and it works. Thanks a lot for your help, your all awesome, and I really appreciate it!!
Ken Cooper
SELECT question FROM polls WHERE date_field < now()
And it works. If I create 10 polls ahead of time, I don't want them to show. But they show when another poll is active, and it works. Thanks a lot for your help, your all awesome, and I really appreciate it!!
Ken Cooper
Thanks for your help!