I'm trying to make a quiz application and I need to retrieve "n" number of questions from a database. I also need to filter the result with categories or difficulties filters.
I don't have any problem if the user make a category choice (for example) :
$size = $_POST['param0'];
$category = $_POST['param1'];
$stmt = $db->prepare("SELECT *
FROM questions_fr
WHERE categories = :categories
LIMIT 0, $size");
$stmt->bindparam(":category", $category);
$stmt->execute();
But what if he wants all the categories ?
Can I do something like that to make only one query in my php file ?
$stmt = $db->prepare("SELECT *
FROM questions_fr
WHERE categories = * (here, select all the categories)
LIMIT 0, $size");
Or should I do something like this ?
(pseudocode)
if ($category != "all_categories")
{
$stmt = $db->prepare("SELECT *
FROM questions_fr
WHERE categories = :categories
LIMIT 0, $size");
}
else if ($category == "all_categories")
{
$stmt = $db->prepare("SELECT *
FROM questions_fr
LIMIT 0, $size");
}