我需要一个好的结构来构建查询,其中搜索参数是使用mysqli 准备好的语句有条件的。$query -> bind_param('sss',$date,$time,$place);
我不知道以后如何申请'sss'
和'$date,$time,$place'
参数。您可以将它们作为变量传递吗?
旧的 MySQL 方式:
<?php
// date is obligatory
$date = mysql_real_escape_string($_GET["date"]);
$query="SELECT * FROM dbase WHERE date='$date'";
// time field is custom
if(!empty($_GET["time"])) {
$time= mysql_real_escape_string($_GET["time"]);
$buildQuery[] = "time='$time'";
}
// place field is also custom
if(!empty($_GET["place"])) {
$place= mysql_real_escape_string($_GET["place"]);
$buildQuery[] = "place='$place'";
}
// building query
if(!empty($build)) {
$query .= ' AND '.implode(' AND ',$build).' ORDER BY date';
}
?>