I would like to create a random link to books / videos / games on Amazon. I am going to store my top 12 items in a database, and update it as I want.
I would like to select 4 different items to show on my front page at random. I can generate 4 different numbers from 12 like this:
Code: Select all
<?php
$num_pick_from = 12;
$num_to_pick = 4;
// Load array with numbers to pick from
for ($i = 0 ; $i < $num_pick_from ; $i++)
{
$input[] = $i;
}
// pick random numbers / keys
$rand_nums = array_rand($input , $num_to_pick);
?>
This returns the numerical keys, which is OK, but it is stored in an array. I then need to extract the numbers and create the right string to use with the database.
Code: Select all
SELECT * FROM shop WHERE id=4 OR id=8 OR id=3 OR id=1
This seems like a lot of overheads. Is there a way of using the array (or AN array) in the query. I remember seeing something which reduced the WHERE clause but I can't find it.
Any ideas?