I want to bind mysqli parameters dynamically using php. The problem I have is adapting my code to do this. I have seen a question which should be helpful to be able to solve this problem which is http://stackoverflow.com/questions/5...mically-in-php but I dont know how to use that code to adapt it into my code. I am really struggling to understand it. It will be easier for me to see somebody adapt my code to fit the bill so then I can understand what is going on.
Can somebody help guide me what I need to do to be able to bind the parameters dynamically in my code? Do I just need to change the bind param method to a call_func_user_array or is it much more than that?
Below is my code:
Thank you and I appreciate your helpCode:$questionquery = "SELECT q.QuestionContent FROM Question q WHERE "; $i=0; $whereArray = array(); $orderByArray = array(); $orderBySQL = ""; $paramString = ""; //loop through each term foreach ($terms as &$each) { $i++; //if only 1 term entered then perform this LIKE statement if ($i == 1){ $questionquery .= "q.QuestionContent LIKE ? "; } else { //If more than 1 term then add an OR statement $questionquery .= "OR q.QuestionContent LIKE ? "; $orderBySQL .= ","; } $orderBySQL .= "IF(q.QuestionContent LIKE ? ,1,0)"; $whereArray[] = "%" . $each . "%"; $orderByArray[] = "%" . $each . "%"; $paramString .= "ss"; } $questionquery .= "GROUP BY q.QuestionId, q.SessionId ORDER BY " . $orderBySQL; $stmt=$mysqli->prepare($questionquery)or die($mysqli->error); ; $stmt->bind_param($paramString, array_merge($whereArray, $orderByArray)); $stmt->execute(); $stmt->bind_result($dbQuestionContent); $questionnum = $stmt->num_rows();![]()


Reply With Quote

Bookmarks