I’m trying to select all rows within my posts table based on 3 requirements.
- The userid from posts table = userid from users table
- The hostid from posts table = userid from users table
- The commentid in the posts table = zero
I want to select all of the rows that meet those requirements. This is the error...
Fatal error: Uncaught Error: Call to a member function fetch_assoc() on bool in C:\xampp\htdocs\loginsystem\includes\posts.inc.php:108 Stack trace: #0 C:\xampp\htdocs\loginsystem\home.php(38): getUploads(Object(mysqli)) #1 {main} thrown in C:\xampp\htdocs\loginsystem\includes\posts.inc.php on line 108
This is my code...
function getUploads($conn) {
$userName = $_GET["user"];
$sqluserid = "SELECT userid FROM users WHERE userName = $userName";
$userid = mysqli_query($conn, $sqluserid);
$sqlusercontent = "SELECT * FROM posts WHERE hostid = $userid AND userid = $userid AND commentid = 0";
$usercontent = mysqli_query($conn, $sqlusercontent);
$postid = 1;
// This is the actual upload content
while ($row = $usercontent->fetch_assoc()) {
echo "<div class='postbox'><p>";
echo $row['title']."<br>";
echo $row['date']."<br>";
echo "<div><img src='posts/".$userid."/".$postid.".*></div>";
echo $row['description']."<br>";
echo "</p>";
echo "</div>";
$postid++;
}
}