Re: [PHP] Joke of the day problem

2007-03-12 Thread Richard Lynch
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:


Your web page then just does:
Joke of the day$joke\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



Re: [PHP] Joke of the day problem

2007-03-10 Thread tedd

At 2:30 PM +0100 3/8/07, 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.


If you're going to do that, then I suspect that you have at least 365 jokes.

If that's the case, then just use the data(z) function to pull of the 
joke who's id is the same as the day of the year. Simple enough. See:


http://hu2.php.net/manual/en/function.date.php

tedd
--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

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



Re: [PHP] Joke of the day problem

2007-03-08 Thread Paul Novitski

At 3/8/2007 05:30 AM, Delta Storm wrote:
I need a script that will take data from MySQL database and display 
one row each day.

...
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.



Hi Delta,

You haven't stated whether you want the database retrieval to be 
random (although constant for one day) or sequential.  If sequential, 
I'd think you could just use the day number as an offset into the recordset:


SELECT Joke FROM Jokes LIMIT $iDay, 1

where $iDay is the current offset of today in the year -- in PHP 
that's date('z').

http://php.net/date

All you'd need is 356 jokes to guarantee a different one each day.

However, it sounds like you want the joke to be extracted at random 
each day.  I'd like to question this approach, as it will undoubtedly 
output some of the same jokes more than once in a given year... 
unless you build in a way of preventing duplicates... or unless your 
client doesn't care if that happens...


What I would suggest is to allow the software to extract jokes 
sequentially using "LIMIT $iDay, 1" and generate the database of 
jokes, in whatever order, once a year.  Rather than randomly 
selecting a record each time you pull a joke from the database, you 
apply any randomness you want once a year when the database is assembled.


Regards,

Paul
__

Paul Novitski
Juniper Webcraft Ltd.
http://juniperwebcraft.com 


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



Re: [PHP] Joke of the day problem

2007-03-08 Thread jekillen


On Mar 8, 2007, at 5: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 :)



I would write the query results to a php file as string variables and 
when someone requests the page
have a date conditional to decide which string to display. Or if you 
want to pull a joke from the database
one at a time just use date to determine which one. For this you may 
have to have a persistent php file

to include to keep track.
Ideas; maybe one looks good?
Best
Jeff k

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



RE: [PHP] Joke of the day problem

2007-03-08 Thread Jim Moseby
> 
> 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.
> 

Maybe I don't understand the application, but this sounds like a job for
cron.  Have cron kick a script off that grabs a record from the database
once each day.

JM

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



Re: [PHP] Joke of the day problem

2007-03-08 Thread clive

Delta Storm wrote:

Hi,

again me with the silly questions...





you could have another table in your database that logs the id of the 
current  joke and the date it was shown on, then simply 'select 
jokeid,dateshown from jokelog order by dateshown limit 1' will get you 
the last joke and when it was used, if the date is yesterdays date then 
get a new joke from the joke table.


you could also have do the same but store 1 entry in a file, file io is 
sometimes quicker than a query on a large db.


--
Regards,

Clive.

Real Time Travel Connections


{No electrons were harmed in the creation, transmission or reading of 
this email. However, many were excited and some may well have enjoyed 
the experience.}


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



[PHP] Joke of the day problem

2007-03-08 Thread Delta Storm

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