I have two tables that share the same row of userid "$u". Table (users) contains all pertinent info on the users, and table (friends) contains info on relationship between user1 and user2 and accepted or blocked friendship.
I want to join the rows of "firstname" and "lastname" from (users) table and add it to the WHERE condition (user1="username" OR user2="username" AND accepted="1") of the relationship from the (friends) table.
Then echo those results of that query into an Unordered Listview in my html. I need help on the proper syntax of putting this together. I am building a social-network and listing out "friends" of each user.
I have it mostly figured out, but it's not outputting anything...probably an error in my syntax...which is why I am posting here for assistance.
Here is my code:
<ul data-role="listview" data-autodividers="true">
<?php
include_once("php_includes/db_conx.php");
$sql = "SELECT * FROM users WHERE username='$u' AND activated='1
INNER JOIN friends on users.id=friends.id
WHERE (friends.user1='$u' OR friends.user2='$u' AND friends.accepted='1')";
$query = mysqli_query($db_conx, $sql);
while ($row = mysqli_fetch_array($query, MYSQLI_ASSOC)) {
echo "<li><a href='user.php?u=".$u."'>". $row['firstname']. ' ' .$row['lastname'] ."</a></li>";
?>
</ul>