Re: Joke of the day problem

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



create table alljokes (joke_id int unsigned auto_increment unique not
null primary key, joke text);
create table daily (whatdate date unique not null primrary key,
joke_id int);

Run a daily cron job that does this:
<?php
  require '/full/path/to/db/connect.inc';
  $query = 'select joke_id from alljokes order by random() limit 1';
  $joke_id = mysql_query($query) or die(mysql_error());
  $joke_id = mysql_result($joke_id, 0, 0);
  $query = "insert into daily (whatdate, joke_id) values(now(),
$joke_id)";
  mysql_query($query) or die(mysql_error());
?>

Your web page then just does:
<?php
  require 'connect.inc';
  $query = 'select joke from daily, alljokes where whatdate = now()
and daily.joke_id = alljokes.joke_id';
  $joke = mysql_query($query) or trigger_error(mysql_error(),
E_USER_ERROR);
  $joke = mysql_result($joke, 0, 0);
  echo "<h2>Joke of the day</h2><p>$joke</p>\n";
?>

YMMV

On Thu, March 8, 2007 8:30 am, Delta Storm wrote:
> Hi,
>
> again me with the silly questions...
>
> I need a script that will take data from MySQL database and display
> one
> row each day.
>
> I have googled, but with no luck.
>
> The database retrieving mechanism is of course clear but I really dont
> know how to do a 24h delay before the next row is displayed.
>
>
> Thanks in advance :)
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux