Page 1 of 1

Easy Mysql Question....

Posted: Sat Apr 01, 2006 3:29 pm
by Deseree
Hi fella's,
I'm coding in php and mysql and it's been a while since I've used mysql, I'm just a bit rusty.

I need to grab 10 rows from a mysql table at random, then mark them as grabbed.... How would I grab at random and NOT pull the entire db into a array ? Efficiency is key! This is a rather large db.

That's what I got so far

Code: Select all

SELECT * FROM `$table` XXXXXXXXXX, LIMIT = 10;

XXXXXX being what I'm missing.....

Thanks in advance!


oh yea, one more easy question I forgot....

I'm using the DATETIME ( http://dev.mysql.com/doc/refman/5.0/en/datetime.html ) variable for a row in this table called, date ,how original, anyways, how can I call rows that are AT LEAST 72 hours since the last time I called them ?

Here's what I got...

Code: Select all

WHERE date>=WHATHERE?
This is the date format I THINK I'm going to use unless anyone can give me advice..

Code: Select all

date("Y-m-d G:i:s");
Thanks again, boy am I rusty with mysql...

Posted: Sat Apr 01, 2006 4:11 pm
by Deseree
XXXXXX = ORDER BY RAND()

Ok answered one of my own questions, going to test in a sec....

how about the date comparison?

OH, btw, what I am doing is this....

I have a database of quotes 150,000 lines long basically that I purchased, and I want to display 10 quotes on the main page, and change every day, and never be the same again until all the quotes are used up, then restart...... advise is very much appreciated...

I have FOUR rows now....

ID
QUOTE
DATE ( DATETIME WHEN LAST CALLED, for tracking )
USED ( USED will be default 0, and set 1 when called and then when db is finished, i will reset ALL USED = 0; I need to remeber how to do that but it's like

Code: Select all

UPDATE TABLE SELECT (USED) SET = 0
YES ? Is that going to work ?

Posted: Sat Apr 01, 2006 5:10 pm
by Deseree

Code: Select all

WHERE `date` < $date_time_now AND ORDER BY RAND() LIMIT 1
I'd really like to know how to make the date comparison.... plus add 72 hours to $date_time_now which is

Code: Select all

$date_time_now = date("Y-m-d G:i:s");
right now...

If I can't figure this out i'll have to resort to unix timestamps which I'd really rather not.....