khanahk Posted August 5, 2012 Report Posted August 5, 2012 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 Quote
khanahk Posted August 6, 2012 Author Report Posted August 6, 2012 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."); } } Quote
falkencreative Posted August 6, 2012 Report Posted August 6, 2012 Have you looked at the documentation for examples for any of these? http://php.net/manual/en/mysqli-result.fetch-array.php http://www.php.net/manual/en/mysqli-result.fetch-row.php http://www.php.net/manual/en/mysqli-result.fetch-object.php Quote
khanahk Posted August 6, 2012 Author Report Posted August 6, 2012 (edited) 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 August 6, 2012 by khanahk Quote
Recommended Posts
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.