Get username where id=1

[php]<?php
$sql = “SELECT
p.id,
p.pid,
p.title,
p.text,
p.main_text,
p.views,
p.date,
c.,
l.
,
u.username
FROM
posts
INNER JOIN
comments c ON p.id = c.pid
INNER JOIN
likes l ON p.id = l.pid
INNER JOIN
username u ON p.pid = u.id
ORDER BY date DESC”;
$result = $conn->query($sql);
while($row = $result->fetch_assoc()) {

	echo"
		<div class='background'>
		<div class='title'><b>". $row['title'] ."</b></div>
		<div style='margin:auto;width:700px;'>
			<div class='text'>". $row['text'] ."</div>
			<a href='topic.php?id=$row[id]' class='view'>View</a>
		</div>	
		<div style='padding-top:30px; padding-left: 20px;padding-right:10px;'>
				<div class='poster'><b><i class='fa fa-eye'></i> ". $row['views'] ." Views</b></div>
				<div class='poster'><b>Posted by</b> $dbusername</div>
				<div class='poster'><b><i class='fa fa-thumbs-up'></i> $likes</b></div>
				<div class='poster'><b><i class='fa fa-comments-o'></i> $comments</b></div>
				<div class='poster' style='float:right;'><b>". $row['date'] ."</b></div>
		</div>
	</div>";}
	?>[/php]

Fatal error: Call to a member function fetch_assoc() on a non-object in C:\xampp\htdocs\GrabPoints2\profile.php on line 44

Line 44: [php]while($row = $result->fetch_assoc()) {[/php]

[php]try {

// your sql code here

} catch ( Exception $e) {
echo “

{$e->getMessage()}

”;
}[/php]

I presume $conn is a mysqli connection object?

Yeah thanks
Could you help me with this?

[php]<a class=‘like’ href=‘like.php?id=$row[id]&myid=".$_SESSION[‘id’]."’> $likes [/php]
so i have made it post pid(post id) and myid

like.php

[php]<?php
include(“connect.php”);
if( isset($_GET[‘id’]) )
{
$id = $_GET[‘id’];
$sql= “INSERT INTO likes (pid,myid) VALUES (’$id’,’’)”;
mysqli_query($conn, $sql);
header(“Location: topic.php?id=$id”);
}
?>[/php]
how should i made if( isset($_GET[‘id’]) ) for 2 or more elements? if( isset($_GET[‘id’]),$_GET[‘myid’]) ) ?

FIXED: SORRY i thought it will make problems for me since last time i failed with this i have fixed this thanks for everything

Sponsor our Newsletter | Privacy Policy | Terms of Service