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 8883571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:50:44+00:00 2026-06-14T20:50:44+00:00

I have a newbies PHP MySQL question, I have 2 tables, members and messages.

  • 0

I have a newbies PHP MySQL question, I have 2 tables, members and messages.

Table ‘members’

+-----------+------+
| MEMBER_ID | NAME |
+-----------+------+
|         1 | Bob  |
|         2 | Ted  |
|         3 | Tom  |
+-----------+------+

Table ‘messages’

+----+------------+--------------+--------------------+
| ID | SENDERS_ID | RECEIVERS_ID |      MESSAGE       |
+----+------------+--------------+--------------------+
|  1 |          1 |            3 | Hello Tom from Bob |
|  2 |          2 |            3 | Hello Tom from Ted |
|  3 |          2 |            1 | Hello Bob from Ted |
+----+------------+--------------+--------------------+

I want to make a query where Tom only having his members.member_id available
can get all of his messages along with name of the sender like this:

+------+--------------------+
| name |      message       |
+------+--------------------+
| Bob  | Hello Tom from Bob |
| Ted  | Hello Tom from Ted |
+------+--------------------+

I have read some examples of joins but do know how to implement them into a MySQL statement.

I can get Tom’s member_id easily but do not know how to proceed further.
I also want to return the result in an array.

  public function getMessages($member_id) {

  $result = mysql_query("SELECT member_id FROM members WHERE member_id = '$member_id'") or die(mysql_error());
    $no_of_rows = mysql_num_rows($result);
    if ($no_of_rows > 0) {
        $result = mysql_fetch_array($result); 
        $receivers_id = $result['member_id'];
        .
        // What can I do here to get the $result that I want?
        .
    }
    $no_of_rows = mysql_num_rows($result);
    if ($no_of_rows > 0) {
        $results = array();
        while(list($results) = mysql_fetch_array($result)) {
            array_push($results, $result);
        } 
        return $results;
    }
}       

Any help would be greatly appreciated,

Thanks

  • 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-06-14T20:50:46+00:00Added an answer on June 14, 2026 at 8:50 pm
    SELECT  c.name,
            b.message
    FROM    members a
            INNER JOIN  messages b
                ON a.member_ID = b.receivers_id
            INNER JOIN members c
                ON b.senders_ID = c.member_ID
    WHERE   a.name = 'Tom'
    
    • SQLFiddle Demo
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

PHP newbie here I have a mysql table called topics, and i'm pulling information
I have only one table in my mySql database for a very basic website
I have a mySQL table of events and want to display them in a
I am a newbie in php, mysql. I have written a hello.php script, which
I am a newbie in MySQL and PHP. I have a HTML form where
Sorry, I want to ask a newbie question :) I have PHP scripts like
I am trying to fetch all rows within a MySQL table that have a
Mysql , php newbie here. Please be nice . I have a list of
I have been playing with PHP & mySQL for a while now, as I
I'm newbie in php mysql and google maps v3. I have a problems in

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.