Hi i am trying to select 10x3 random id's from 3 different categories, but is there a smarter way to achieve this in just one query instead of 3 different queries?
$sql = "SELECT id FROM rating WHERE category IN (1) ORDER BY RAND() LIMIT 10";
$result1 = $dbCon->query($sql);
$arr;
while ($obj = $result1->fetch_object()) {
$arr[] = $obj->id;
}
$sql = "SELECT id FROM rating WHERE category IN (2) ORDER BY RAND() LIMIT 10";
$result1 = $dbCon->query($sql);
while ($obj = $result1->fetch_object()) {
$arr[] = $obj->id;
}
$sql = "SELECT id FROM rating WHERE category IN (3) ORDER BY RAND() LIMIT 10";
$result1 = $dbCon->query($sql);
while ($obj = $result1->fetch_object()) {
$arr[] = $obj->id;
}
var_dump($arr);