Hi I am new to PDO, and am learning its structure.
How can I prepare a string with multiple choices from query strings to perform search on mysql? I understand the prepare statement and binding the string, but not sure how to create the string when there is nothing to bind ($_GET is empty) to list all data.
This is my current working code.
// Start Listing
$query = "SELECT * FROM cars WHERE active=‘1’ ";
if($_GET[‘make’]){ $query .= " AND make
=‘“.$_GET[‘make’].”’ “; }
if($_GET[‘model’]){ $query .= " AND model
='”.$_GET[‘model’]."’ "; }
switch($_GET[‘view’]){
case “low”: $query .= " ORDER BY value"; break;
case “high”: $query .= " ORDER BY value DESC"; break;
default: break;
}
$query .= " LIMIT “.$shownum.”, 10;";
$result = mysqli_query($mysqli, $query);