views:

61

answers:

2

hi anyone know about how to use Random wallpaperid between limit IDs using RAND() php msql

i use this but its RAND() whole database

$sql_wallpaper = "SELECT * FROM wallpaper WHERE RAND()>0.9 ORDER BY RAND() LIMIT 0,5";
$res_wallpaper = mysql_query($sql_wallpaper);

reply please

+2  A: 

Do you mean this?

$sql_wallpaper = "SELECT * FROM wallpaper WHERE id>Min AND id<Max ORDER BY RAND() LIMIT 1";
$res_wallpaper = mysql_query($sql_wallpaper);
Snigger
I MEAN like that i need random wallpapers from ID 1 to ID 100 else but using RAND() between ID 1 to 100 reply
Hassan
A: 

Your question indicates you're using PHP.

Why not just use this?

$rand_id = rand(1, 100);

and then

SELECT * FROM wallpaper WHERE id = $rand_id LIMIT 1
Frederick
That would be fine if you'd be 100% sure that no record has been deleted from database. Imagine that you delete row `#51`. Then if `$rand_id` will contain `51` no record will be returned.
Crozin
work good but in limit 1 and 12 its show only one record...optmize it
Hassan
i put limit 12 but its show one record help
Hassan
No reply ? please reply
Hassan
Oh, if you want MULTIPLE results then the previous answer works better.For one: `SELECT * FROM wallpaper WHERE id >= 1 AND id <= 100 ORDER BY RAND() LIMIT 1`For 12 records `SELECT * FROM wallpaper WHERE id >= 1 AND id <= 100 ORDER BY RAND() LIMIT 12`
Frederick
If i start from last added ID then what i do SELECT * FROM wallpaper WHERE id >= LastaddedID AND id <= UPto100 ORDER BY RAND() LIMIT 12 what i do like this?
Hassan
I don't know what you mean by LastaddedID. If you add a new wallpaper to the table and the NEW (last added) row has an ID that is less than 100, you will get 0 results from the query since there will be no IDs after LastaddedID. You need to think about what you're querying.
Frederick