Jump to content
Stef's Coding Community

MySQLi store_result question


Recommended Posts

I've got

 

function renderTopics($cat)
{
	global $Database;

	if ($stmt = $Database->prepare("SELECT * FROM topics WHERE category = ?");
	{
		$stmt->bind_param("s", $cat);
		$stmt->execute();
		$stmt->store_result();
	}
	else
	{
		die("Could not prepare MySQLi statement.");
	}
}

 

The question is... how do I access the results?! How can I set it to an array or whathaveyou?

 

Thanks

Link to post
Share on other sites

This is currently not working but may help you understand what I'm going for:

 

function renderTopics($cat)
{
	global $Database;

	if ($stmt = $Database->prepare("SELECT * FROM topics WHERE category = ?"))
	{
		$stmt->bind_param("s", $cat);
		$stmt->execute();
		$stmt->store_result();
		$array = $stmt->store_result();
		while ($row = $array->fetch_row())
		{
			printf("%s\n", $row[0]);
		}

	}
	else
	{
		die("Could not prepare MySQLi statement.");
	}
}

Link to post
Share on other sites

Ben,

 

You are most helpful...! the following now works to render every row within the specified SQL selection

function renderTopics($cat)
{
	global $Database;

	$query = "SELECT * FROM topics WHERE category = '$cat'";

		$result = $Database->query($query);
		while ($row = $result->fetch_array(MYSQLI_BOTH))
		{
			do {
			print $row['name']."-----".$row['poster']."------".$row['category']."---".$row['created_date']."<br />";
			} while ($Database->next_result());
		}
		$result->free();
		$Database->close();


}

Thanks

Edited by khanahk
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

Loading...
×
×
  • Create New...