Jump to content

SELECT by the hour!


Jumpy09

Recommended Posts

I'm trying to set up a time-based query which will allow users to sponsor themselves for the duration of an hour.

 

Since I code backwards, I'd figure I would get the query out of the way as the script behind inserting may be a bit more difficult than I would like.

 

So, let's say Bob has a sponsorship at 9pm, and Bill has one at 10pm.

From 9PM to 9:59PM Bob should have his sponsorship, and at 10pm... of course on refresh...  Bill should begin his.

 

I have no idea what to even look for, as anything I've typed in .. comes to various other results.

 

Anyone have an idea?

Link to comment
https://forums.phpfreaks.com/topic/204463-select-by-the-hour/
Share on other sites

I have DateTime as the showtime.  I figure it was wrong because it would pull anything on that hour, if it had happened to work.

 

Table Layout:

 

specialty_sponsor

 

sponsorid -- uid -- message -- showtime -- date

 

SponsorID - Is the sponsor Identification, basically the primary key since nothing else can be made primary.

UID -- User Identifaction - Shows who will be hosted during that hour.

Message -- Should speak for itself.

Showtime -- datetime formated time period of when someone should show.

Date -- Date it was added to the database.  I was planning a Countdown to show users when they are being sponsored.

 

I'll check those on Google, the ideas you submitted.  It will come in handy for differences.

Link to comment
https://forums.phpfreaks.com/topic/204463-select-by-the-hour/#findComment-1070811
Share on other sites

I've gotten this!

 

<?php

$time = time() + 3600;
$sponsor = mysql_query("SELECT * FROM `specialty_sponsors` WHERE `showtime` < '$time' AND `showtime` + 3600 > 'time()' ORDER BY showtime LIMIT 1") or die(mysql_error());
$sponsorrow = @mysql_fetch_array($sponsor);

if($sponsor == true) {
$sponsoruid = $sponsorrow['uid'];
$sponsormessage = $sponsorrow['message'];
$sponsorshowtime = $sponsorrow['showtime'];

} else if($sponsor == false) {
$sponsormessage = 'Currently there isn\'t a Sponsor!';

}

?>

 

It doesn't display anything though, and --

 

$sponsor = mysql_query("SELECT * FROM `specialty_sponsors` WHERE `showtime` < 'time() + 3600' ORDER BY showtimeDESC LIMIT 1") or die(mysql_error());

 

Shows only the last result, but if no one is hosting a sponsorship at 2pm, I don't want it showing anyone.

Link to comment
https://forums.phpfreaks.com/topic/204463-select-by-the-hour/#findComment-1070886
Share on other sites

If only we could modify out posts.

 

 

I now have:

$time = time() + 3600;
$sponsor = mysql_query("SELECT * FROM `specialty_sponsors` WHERE `showtime` < '$time' AND `showtime` + 3600 > 'time()' ORDER BY showtime LIMIT 1") or die(mysql_error());
$sponsorrow = @mysql_fetch_array($sponsor);

if(mysql_num_rows($sponsor) == 0) {
	 $sponsormessage = 'Currently there isn\'t a Sponsor!';
} else {
  $sponsoruid = $sponsorrow['uid'];
$sponsormessage = $sponsorrow['message'];
$sponsorshowtime = $sponsorrow['showtime'];
}

 

Still doesn't work, but shows there isn't a sponsor.

Link to comment
https://forums.phpfreaks.com/topic/204463-select-by-the-hour/#findComment-1070892
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.