Thursday, 15 March 2012

php - GROUP BY and ORDER BY clause coming after prepare statement (mysqli) -



php - GROUP BY and ORDER BY clause coming after prepare statement (mysqli) -

i have query below dynamic clause having issue placing grouping , order clause. don't think beingness triggered @ because prepare statement ahead of clauses. not allow me place clause line above prepare statement or gives me error stating undefined questions in different line. question should grouping , order clause correctly placed?

code:

$selectedstudentanswerqry = " select sa.studentid, studentalias, studentforename, studentsurname, q.sessionid, ... pupil st ... "; // empty $where = array('q.sessionid = ?'); $parameters = array($_post["session"]); $parametertypes = 'i'; //check if post empty // check whether specific pupil selected $p_student = empty($_post["student"])?0:$_post["student"]; // if $_post['student'] either 0 or empty $p_student 0 echo $p_student; switch($p_student){ case 0: //dont' add together filters break; default: $where[] = 'sa.studentid = ?'; $parameters[] .= $_post["student"]; $parametertypes .= 'i'; } // if added $where in of conditionals, need clause in // our query if(!empty($where)) { $selectedstudentanswerqry .= ' ' . implode(' , ', $where); global $mysqli; $selectedstudentanswerstmt=$mysqli->prepare($selectedstudentanswerqry); // need phone call bind_param 1 time if (count($where) == 1) { $selectedstudentanswerstmt->bind_param($parametertypes, $parameters[0]); } else if (count($where) == 2) { $selectedstudentanswerstmt->bind_param($parametertypes, $parameters[0], $parameters[1]); } } $selectedstudentanswerqry .= " grouping sa.studentid, q.questionid order studentalias, q.sessionid, questionno ";

move prepare statement , if statements containing bind_param() underneath grouping by/order clause. have closing } above $selectedstudentanswerqry can moved above if (count($where) == 1)

php mysqli

No comments:

Post a Comment