so you want to have six random elements of a table and then afterwards
the corresponding values ???
i think you need a sub-query ( or sth. equivalent )
i dont know, what your tables look like, but i used code like this for a script:
$inString='';
// this gets me 6 random elemts of a table, the key-row is named "id"
$inQuery = "SELECT id FROM `timetable`where hub='EGPF' AND departure='EGPF' AND
rankneeded <= '9' ORDER BY RAND() ASC LIMIT 6;";
while( $row=mysql_fetch_row( $inQuery )
{
if ( strlen ( $inString > 0 ) )
{
$inString .= ','; // add a comma, if more than one value present
}
$inString .= $row[ 0 ];
}
// now we have the value for the "in"-part in the next sql
$query = "SELECT * FROM `timetable` as a, timetable as b WHERE a.id=b.id AND a.id IN ( ". $inString ." ) ";
with that you have a dynamic "join" on the tables ( with the random elemts )
i think the easiest sql would be:
( does the same, but on a sql-basis BUT not functioning on mysql V3... )
SELECT from timetable as a, tiemtable as b WHERE a.id=b.id AND a.id in ( SELECT FROM timetablewhere hub='EGPF' AND departure='EGPF' AND rankneeded <= '9' ORDER BY RAND() ASC LIMIT 6; )