Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

Sorry, Last Question, PROMISE!! - Selecting Stuff database

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Sorry, Last Question, PROMISE!! - Selecting Stuff database

Postby Kenneth » Fri Aug 09, 2002 3:12 pm

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
Kenneth
New php-forum User
New php-forum User
 
Posts: 40
Joined: Fri Aug 09, 2002 11:53 am
Location: Rochester, NY

Postby Jay » Fri Aug 09, 2002 5:04 pm

Order by date and skip the first row? Or have I completely misunderstood you?
Jay
 

Postby Kenneth » Fri Aug 09, 2002 5:24 pm

Jay I get that, but how do I skip a row, code wise? Thanks a lot, really appreciate it.

Ken Cooper
Kenneth
New php-forum User
New php-forum User
 
Posts: 40
Joined: Fri Aug 09, 2002 11:53 am
Location: Rochester, NY

Postby DoppyNL » Fri Aug 09, 2002 11:51 pm

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
DoppyNL
 

Postby Kenneth » Sat Aug 10, 2002 12:04 pm

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
Kenneth
New php-forum User
New php-forum User
 
Posts: 40
Joined: Fri Aug 09, 2002 11:53 am
Location: Rochester, NY

Postby DoppyNL » Sat Aug 10, 2002 12:37 pm

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 :D (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:
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
DoppyNL
 

Postby Kenneth » Sat Aug 10, 2002 1:06 pm

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
Kenneth
New php-forum User
New php-forum User
 
Posts: 40
Joined: Fri Aug 09, 2002 11:53 am
Location: Rochester, NY

Postby Jay » Sat Aug 10, 2002 10:58 pm

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)
Jay
 

Postby Kenneth » Sun Aug 11, 2002 7:23 am

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
Kenneth
New php-forum User
New php-forum User
 
Posts: 40
Joined: Fri Aug 09, 2002 11:53 am
Location: Rochester, NY


Return to PHP coding => General

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron