Jump to content

call_user_func_array() with dynamic mysql query error


disciple10

Recommended Posts

The page that I'm currently working on has a form which allows, through a series of check boxes and text entry fields, a dynamic mysql query to be created. The php code constructs the query based on which fields the user updated in order to find a specific user in the database. Everything was working fine until I started to only display part of the result set. In order to display a message similar to "Displaying 12-25 of 65 results." I ran the query twice. Once to get the total number of results, and once to only get the specified set.

 

The code for the section producing the error is included below. The elseif statement works as desired, as does the initial query of the if statement.

	if (isset($sql) && $sql !=""){
	$sql = "SELECT DISTINCT users.StudentID FROM users lEFT JOIN events ON users.StudentID=events.StudentID WHERE" . $sql;
	$stmt = $mysqli->prepare($sql);
	call_user_func_array(array(&$stmt, 'bind_param'), $array_of_params);
	$stmt->execute();
	$stmt->store_result();
	$total= $stmt->num_rows;
	$stmt->close();
	$sql = "SELECT DISTINCT users.StudentID,users.FirstName,users.LastName,users.Email,users.Phone,users.Texting,users.Admin,users.HDHS,users.Sex,users.Confirmation FROM users lEFT JOIN events ON users.StudentID=events.StudentID WHERE" . $sql . " ORDER BY LastName,FirstName LIMIT " . $_GET['start'] . ",12";
	$stmt = $mysqli->prepare($sql);
	call_user_func_array(array(&$stmt, 'bind_param'), $array_of_params);
	$stmt->bind_result($row['StudentID'],$row['FirstName'],$row['LastName'],$row['Email'],$row['Phone'],$row['Texting'],$row['Admin'],$row['HDHS'],$row['Gender'],$row['Confirmation']);

}
elseif(isset($_GET['submit']) || isset($_GET['earlier']) || isset($_GET['later'])){
	$stmt = $mysqli->prepare("SELECT StudentID,FirstName,LastName,Email,Phone,Texting,Admin,HDHS,Sex,Confirmation FROM users ORDER BY LastName,FirstName");
	$stmt->bind_result($row['StudentID'],$row['FirstName'],$row['LastName'],$row['Email'],$row['Phone'],$row['Texting'],$row['Admin'],$row['HDHS'],$row['Gender'],$row['Confirmation']);
	$stmt->execute();
	$stmt->store_result();
	$total= $stmt->num_rows;
	$stmt = $mysqli->prepare("SELECT StudentID,FirstName,LastName,Email,Phone,Texting,Admin,HDHS,Sex,Confirmation FROM users ORDER BY LastName,FirstName LIMIT " . $_GET['start'] . ",12");
	$stmt->bind_result($row['StudentID'],$row['FirstName'],$row['LastName'],$row['Email'],$row['Phone'],$row['Texting'],$row['Admin'],$row['HDHS'],$row['Gender'],$row['Confirmation']);
	$stmt->execute();
}

 

If anyone would be willing to help me out here it would be greatly appreciated. If you need more information let me know. Thank you!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.