RE: Date Woes

2002-10-18 Thread Brent Macnaughton

PHP already has a function that will convert a textual date into a unix
timestamp. 

-

strtotime
(3.0.12 - 3.0.18 only, PHP 4 = 4.0.0)

strtotime --  Parse about any English textual datetime description into a
UNIX timestamp 
Description

int strtotime (string time [, int now])


The function expects to be given a string containing an English date format
and will try to parse that format into a UNIX timestamp relative to the
timestamp given in now, or the current time if none is supplied. Upon
failure, -1 is returned. 

-

You can then use the PHP function date() to format the unix timestamp as a
mySQL timestamp, or you can use the mySQL function FROM_UNIXTIME to so the
same.

I have used strtotime() to convert the textual datetime exported from MSSQL
into a unix timestamp successfully.

Bernt.

-Original Message-
From: Iain Lang [mailto:limpingwithbothfeet;metro800.co.uk]
Sent: Thursday, October 17, 2002 10:26 AM
To: Serge Paquin; [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Subject: RE: Date Woes


.
Could we see this php routine, please?  Or can you post it to a newsgroup?

Yooors,

Iain Lang.

At 18:23 15/10/02 -0400, Serge Paquin wrote:
I have written a very poor and inflexable PHP function to do this outside
the database.  I have not played with doing my own functions in mySQL but
your suggestion is well taken.  I believe that I will attempt to create a
function for mySQL that is more compatible and flexable.  Good suggestion
not sure why I didn't think of it :)

Serge.


-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail [EMAIL PROTECTED]
To unsubscribe, e-mail
[EMAIL PROTECTED]
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail [EMAIL PROTECTED]
To unsubscribe, e-mail [EMAIL PROTECTED]
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php




Selecting records with the highest value no greater than x

2002-02-15 Thread Brent Macnaughton


I need some help here. Let's see if I can clearly describe it.

I have a database containing news stories.  Each story is assigned a
rating (1 thru 5)  indicating its importance. (A story with a rating of 5
is more important than a story with rating  of 1.)

Now, lets say that there are ten stories in the DB with a rating of 4 and I
want to randomly pick one of those stories.  I am doing something like this:

SELECT * FROM NEWS WHERE RATING=4 ORDER BY RAND() LIMIT 1

That gives me the results I want, but there is a problem.  There is no
guarantee that there will be any stories in the DB with a rating of 4.  If
that happens, I want to randomly select a story with the next rating (three
in this case) and if there are no stories with a rating of 3 as well, I want
to select a story with a rating of 2, and so on and so forth.

I would really like to be able to do this with one SELECT statement as
opposed to running the above query over and over again, each time
decrementing the value of the rating until a record is returned.

Any Suggestions?

Thanks.

Brent Macnaughton

-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail [EMAIL PROTECTED]
To unsubscribe, e-mail [EMAIL PROTECTED]
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php