Seems like it should be easy...
Jared
jared at trios.org
Thu Jan 9 12:16:51 CST 2003
It is easy, yes. PHP pseudocode is:
<?php
$today = date('y/m/d');
$sql = "select opentime, saleitem from tblsalesinfo where datetime > $today";
mysql_connect("helo","hi","hola");
$recordset = mysql_query($sql);
if (!$recordset) {
die("Today our database is browk.");
} else {
$opentime = $recordset[0];
echo "Today we open at $recordset[0], and our sale item is: $recordset[1]";
}
?>
Your MySQL database will be equally concise.
(Each record contains: recordid, datetime, opentime, saleitem).
See the first example at this location, for code that will actually work.
Modify it to suit your needs:
http://www.php.net/manual/en/function.mysql-fetch-row.php
-Jared
--------------------------------------------------------------
Seth Dimbert wrote:
> LUGNuts,
>
> I'm not a programmer.
>
> But it seems to me that it would be pretty easy to write a small Perl or php
> program to do what I want it to do.
>
> All I want is to have a small script that looks into a simple database
> (could be flat-file) and looks up information based upon the current time
> and date, then displays that information.
>
> Let me offer an example, because my actual need is too complicated to
> explain.
>
> Let's say that visitors to my website want to know what time my store is
> open, and what the "Sale Item of the Day" is. So, the database would look
> like this:
>
> Date Range Time Sale Item
> ---------------------------------------
> 01/01 - 01/07 8:00 am Apples
> 01/08 - 01/14 7:00 am Oranges
> 01/15 - 01/21 4:00 pm Watermelon
> Etc...
>
> Is that clear? On January 3, when the page loads, the script runs and
> returns: "This week, we open at 8:00 am and Apples are on sale." On January
> 8, the page would change to, "This week, we open at 7:00 am and Oranges are
> on sale."
>
> I need the script to check the current (server) time and date against the
> date range in the database every time it's called... Every time the page is
> called.
>
> Is that hard? As a non-programmer, it doesn't seem hard to me! :)
>
> Can anyone point me at a canned solution or help me create one?
>
> Thanks!
>
> -SD
More information about the Kclug
mailing list