Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3878936
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T22:40:09+00:00 2026-05-19T22:40:09+00:00

I have these 3 tables: users table(PK user_id) Fields: user_id, user_first_name, user_last_name, username, user_email…etc

  • 0

I have these 3 tables:

users table(PK user_id)

Fields: user_id, user_first_name,
user_last_name, username,
user_email…etc

pals table (FK user1_id, user2_id from PK user_id in users table)

pal_id    user1_id    user2_id          status        timestamp
7           98              97               0     2011-02-02 21:44:28
8           92              98               1     2011-02-04 08:06:00
9           95              92               0     2011-02-04 08:05:54
10         97              92               1     2011-02-04 08:05:28
11         97              95               1     2011-02-04 08:06:33

picture table (FK user_id from PK user_id in users table)

picture_id  picture_url             picture_thumb_url               user_id  avatar         timestamp
73      ../User_Images/66983.jpg    ../User_Images/Thumbs/66983.jpg     92     0    2011-02-03 21:52:02
74      ../User_Images/56012.jpg    ../User_Images/Thumbs/56012.jpg     92     0    2011-01-25 12:09:58
75      ../User_Images/58206.jpg    ../User_Images/Thumbs/58206.jpg     95     0    2011-01-22 22:12:35
76      ../User_Images/85428.jpg    ../User_Images/Thumbs/85428.jpg     98     0    2011-01-23 23:50:16
77      ../User_Images/42325.jpg    ../User_Images/Thumbs/42325.jpg     98     0    2011-01-24 00:11:15
78      ../User_Images/73154.jpg    ../User_Images/Thumbs/73154.jpg     98     1    2011-01-24 00:11:15
81      ../User_Images/92865.jpg    ../User_Images/Thumbs/92865.jpg     92     0    2011-01-31 18:24:34
82      ../User_Images/75611.jpg    ../User_Images/Thumbs/75611.jpg     92     0    2011-01-26 18:08:52
83      ../User_Images/74829.jpg    ../User_Images/Thumbs/74829.jpg     95     0    2011-02-01 20:48:48
84      ../User_Images/5987.jpg     ../User_Images/Thumbs/5987.jpg      92     1    2011-02-03 21:52:02

I am making a social networking site where I want to have a user’s pals shown in a PHP generated table. I want to show pal thumbnails and other information below these thumbnails so that if you click on a thumbnail, it takes you to that user’s profile.

From above, user 92 is pals with user 98 because they have confirmed friendship(shown as status = ‘1’)

user1_id in the pals gets the user id of the initiator of the friendship. For pal_id=8, user 92 requested friendship, 95 confirmed it. Had user 95 requested friendship and it had been confirmed, user2_id would be reading 92. User 92 has another pal, user 97. 97 initiated the friendship.

Users can have pictures, stored in the picture table above. A user selects his avatar from his pictures…that is done by setting one of his picture.avatar = ‘1’.

Now, how will I make my PHP query to show pal thumbnails and info?

I have this so far(my desired results are way off!)

<?php require_once('Connections/connections.php'); ?>
<?php
//query username
$user_id = $_SESSION['UserSession'];
$user_id = mysql_real_escape_string($user_id);
mysql_select_db($database_connections, $connections);
$query_user_info = "SELECT username FROM users WHERE user_id='$user_id'";
$user_info = mysql_query($query_user_info, $connections) or die(mysql_error());
$row_user_info = mysql_fetch_assoc($user_info);

bla bla bla

<?php
while ($pal_no = mysql_fetch_assoc($pal_no_result))
{
    //get pal info
    $query_pal_info = "SELECT * FROM users INNER JOIN pals ON (pals.user1_id = users.user_id) OR (users.user_id = pals.user2_id) 
    INNER JOIN picture ON picture.user_id = users.user_id AND picture.avatar = '1' WHERE users.user_id = '$user_id'";
    $pal_info = mysql_query($query_pal_info , $connections) or die(mysql_error());
    $totalRows_pal_info = mysql_num_rows($pal_info);

    //echo table with pal information
    echo "\n<table>";
    $j = 5;
    while ($row_pal_info = mysql_fetch_assoc($pal_info))
    {
        if($j==5) echo "\n\t<tr>";
        $thumbnail_user = $row_pal_info['picture_thumb_url'] != '' ? $row_pal_info['picture_thumb_url'] : '../Style/Images/default_avatar.png';
        echo "<td width='100' height='100' align='center' valign='middle'><a href = 'user_view.php?user_id2={$row_pal_info['user_id']}'>
        <img src='/NNL/User_Images/$thumbnail_user' border='0'/></a></td>\n";
        $j--;
        if($j==0) {
        echo "\n\t</tr>\n\t<tr>";
        $j = 5;
        } 
    }
    if($j!=5) echo "\n\t\t<td colspan=\"$j\"></td>\n\t</tr>";
    echo "\n</table>";
}
?>

Ze problem iz here:

$query_pal_info = "SELECT * FROM users INNER JOIN pals ON (pals.user1_id = users.user_id) OR (users.user_id = pals.user2_id) 
    INNER JOIN picture ON picture.user_id = users.user_id AND picture.avatar = '1' WHERE users.user_id = '$user_id'";

How do I fix it? Thanks in advance guys.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T22:40:09+00:00Added an answer on May 19, 2026 at 10:40 pm

    This is my final answer! And this is working perfectly!!

    class MySQLDatabase{
        private  $hostname = 'localhost';
        private  $username = 'root';
        private  $password = 'password';
        private  $dbname = 'test';
        private $result;
    
        private $connection;
    
        function __construct()
        {
            $this->connect();
        }
    
        public function connect()   
        {
            $this->connection = mysql_connect($this->hostname, $this->username, $this->password);
            if (!$this->connection)
                die(mysql_error());         
    
            if (!mysql_select_db($this->dbname))
                die(mysql_error());
        }
    
        public function query($sql)
        {
            if(!$this->connection)
                $this->connect();
            $this->result = mysql_query($sql);      
            if(!$this->result)
                die(mysql_error());
            return $this->result; 
        }
    
        public function numOfRows()
        {
            return mysql_num_rows($this->result);
        }
    
        public function fetchArray($resultset)
        {
            return  mysql_fetch_assoc($resultset);
        }
    }
    
    $mysqldb = new MySQLDatabase();
    
    $userid = 92;
    
    
    $sql1 = "SELECT pals.user2_id AS pals_id1, users.user_first_name AS pals_first_name, ".
        " users.user_last_name AS pals_last_name, picture.picture_thumb_url AS ".
        "  picure, picture.avatar AS avatar FROM pals INNER JOIN (users LEFT JOIN picture ".
        " on picture.user_id = users.user_id) ON users.user_id = pals.user2_id WHERE pals.user1_id".
        " =".$userid." AND picture.avatar = 1 GROUP BY pals_id1;";
    
    $palinfo1 = $mysqldb->query($sql1);
    
    
    $sql2 = "SELECT pals.user1_id AS pals_id1, users.user_first_name AS pals_first_name, ".
        " users.user_last_name AS pals_last_name, picture.picture_thumb_url AS picure, picture.avatar".
        " AS avatar FROM pals INNER JOIN (users LEFT JOIN picture on picture.user_id = users.user_id)".
        " ON users.user_id = pals.user2_id WHERE pals.user2_id = ".$userid." AND picture.avatar = 1 GROUP BY pals_id1;";
    $palinfo2 = $mysqldb->query($sql2);
    
    
    echo "<table>";
    
    while($palinfo = $mysqldb->fetchArray($palinfo1)){
        echo "<tr>";
    
        foreach($palinfo as $info => $value){
            echo "<td>$value</td>";
        }
    
        echo "</tr>";
    }
    
    while($palinfo = $mysqldb->fetchArray($palinfo2))
    {
        echo "<tr>";
    
        foreach($palinfo as $info => $value){
            echo "<td>$value</td>";
        }
    
        echo "</tr>";
    }
    
    
    echo "</table>";
    

    And also you need at least two queries to display all friend list. Best of luck with your project.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an SQL Server DB with a table with these fields: A bit
I have two tables users - id - name - email users_groups - user_id
I have these tables: customer -------- customer_id int name varchar(255) order ----- order_id int
I have these tables: Projects(projectID, CreatedByID) Employees(empID,depID) Departments(depID,OfficeID) Offices(officeID) CreatedByID is a foreign key
I have these 3 tables + data: items : itemId, itemName data: 1, my
Does anyone have any suggestions for creating meta tables in a database? These tables
I have tree tables, Customer, Invoice and InvoiceRow with the standard relations. These I
I'm currently dynamically building an asp:table which contains checkboxes these checkboxes have a CheckChanged
I have a table that contains tasks and I want to give these an
Lets say I have two tables. class CreateUsers < ActiveRecord::Migration def self.up create_table :users

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.