Post vars
$institute = $_POST['institute'];
if (isset($_POST['sections'])) {
$sections = $_POST['sections'];
}
if (isset($_POST['division'])) {
$division = $_POST['division'];
}
if (isset($_POST['level'])) {
$level = $_POST['level'];
}
//check empty var
$where = "WHERE a.institute =?";
$bind = "i";
$prams = "$institute, ";
if (!empty($sections)) {
$where .= "AND a.section = ?";
$bind .= "i";
$prams .= "$sections, ";
}
if (!empty($division)) {
$where .= "AND a.division =?";
$bind .= "i";
$prams .= "$division, ";
}
if (!empty($level)) {
$where .= "AND a.phase =?";
$bind .= "i";
$prams .= "$level";
}
//var_dump($institute, $sections, $division, $level);
var_dump($bind);
//$getSearch = $db->prepare("SELECT * FROM student_basic_info WHERE institute =? AND section = ? AND division =?");
$getSearch = $db->prepare("SELECT
a.*, a.id AS stud_id, b.id, b.ins_name, c.id, c.sec_name, d.id, d.div_name
FROM student_basic_info AS a
JOIN institutes AS b ON (a.institute = b.id)
CROSS JOIN ins_sections AS c ON (a.section = c.id)
CROSS JOIN ins_division AS d ON (a.division = d.id)
$where GROUP BY a.id
");
$studSearch = array();
$getSearch->bind_param("'".$bind."'", $prams);
if ($getSearch->execute()) {
$results = $getSearch->get_result();
while ($vStud = mysqli_fetch_array($results)) {
$studSearch[] = $vStud;
?>
得到了
(!)致命错误:在a上调用成员函数bind_param() 第59行的非对象
第59行是
$getSearch->bind_param("'".$bind."'", $prams);
解决Call to a member function bind_param()
现在得到了Warning: mysqli_stmt::bind_param(): Number of elements in type definition string doesn't match number of bind variables
答案 0 :(得分:1)
看起来$getSearch
为空(false)。检查您的prepare
功能。它应该在成功时返回true
。
if ($getSearch = $db->prepare(...)) {
$getSearch->bind_param(...);
...
}
else {
printf("Errormessage: %s\n", $db->error);
}
答案 1 :(得分:1)
您需要添加AND
条件的空格;现在您的sql无效,prepare
将失败:
$where .= " AND a.section = ?";
^ here
// etc.
但是,现在你的绑定会失败,你不能连接你的值并发送一个长字符串作为第二个参数。您需要单独绑定每个值。