If I have a 1,000 items in a table and I want to get a random number .. $randnumber = '700'; How could I select items: 700,699,698,697,696 from the table with 1 query that isn't where id='', is this possible? I was trying less than but it gets 1,2,3,4,5..
Yes, but the table has over 100,000 rows so I'm trying to do it in a way that won't put as high a load in the processor?
PHP, then. <?php $row_count = mysql_num_rows(mysql_query("SELECT * FROM table")); //unless you want to hard-code the number $random_row_number = rand(1, $row_count); $random_row = mysql_fetch_assoc(mysql_query("SELECT * FROM table WHERE id=$random_row_number")); ?> Code (markup): Loop that or pre-fill an array with as many rows as you want to retrieve. That's the simplest solution I can come up with quickly.
SELECT * FROM table Code (markup): This is going to create a lot of data flowing, all 100,000 rows being returned every time. Is your ID column a sequential number? If it is then SELECT Max(RowID) FROM TableName; Code (markup): would be much better. You can then use the code to do the randomisation and then select those X rows. Alternative create a stored procedure that does the same.
Thanks for that. I was going to write SELECT id but wasn't sure of the field names. I should have mentioned that because that's potentially a LOT of data haha.