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

  • SEARCH
  • Home
  • 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 8057921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:11:19+00:00 2026-06-05T09:11:19+00:00

I have a query which grabs all users from the wait table based on

  • 0

I have a query which grabs all users from the wait table based on $oneid. This works just fine but I would like to count how many messages a user leaves. These are in another table one_msg.

function waiting_users($oneid)
    {

    $query_str ="SELECT a.user_id, b.email, b.username, b.fbook, c.user_id as saved_user, d.type as user_type,
                    FROM wait a 
                    LEFT JOIN users b ON a.user_id=b.id
                    JOIN user_profiles d ON a.user_id=d.user_id
                    LEFT JOIN save_one c ON a.user_id=c.user_id AND c.one_id=?
                    WHERE a.post_id = ? 
                    ORDER BY a.date ASC";
}
            $query = $this->db->query($query_str, array( $oneid, $oneid ) );

one_msg table

+----+--------+---------+---------+---------------------+
| id | one_id | host_id | user_id | date                |
+----+--------+---------+---------+---------------------+
|  3 |    127 |     268 |     270 | 2012-06-11 18:57:58 | 
|  4 |    127 |     268 |     270 | 2012-06-11 21:45:11 | 
|  5 |    127 |     268 |     270 | 2012-06-12 09:10:01 | 
+----+--------+---------+---------+---------------------+

So I am trying to count the messages from one_msg like this but it’s returning the same value for all users.

function waiting_users($oneid)
    {

    $query_str ="SELECT a.user_id, b.email, b.username, b.fbook, c.user_id as saved_user, d.type as user_type,
                    (SELECT COUNT(id) FROM one_msg WHERE post_id = ?) AS count
                    FROM wait a 
                    LEFT JOIN users b ON a.user_id=b.id
                    JOIN user_profiles d ON a.user_id=d.user_id
                    LEFT JOIN save_one c ON a.user_id=c.user_id AND c.one_id=?
                    WHERE a.post_id = ? 
                    ORDER BY a.date ASC";

}
            $query = $this->db->query($query_str, array( $oneid, $oneid, $oneid ) );
  • 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-05T09:11:22+00:00Added an answer on June 5, 2026 at 9:11 am

    Your sub-query should check for the user_id instead of post_id (which does not exist in one_msg, so it is taken from wait:

    (SELECT COUNT(id) FROM one_msg m WHERE m.user_id = a.user_id) AS count
    

    instead of

    (SELECT COUNT(id) FROM one_msg WHERE post_id = ?) AS count
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this query which returns all rows from a table: select Cost, Name,
I have the code below which grabs data from a table based on what
I have this query which works correctly in MySQL. More background on it here
I have a query which works fine in MySQL, but when I run it
I have a query which works fine var queryItems = rawQuery.ObsDataResultList.AsQueryable().Where(Name = @0 AND
I have a query which produces a list of orders like this: Invoice Description
I have a query which searches two separate fields in the same table... looking
I have a query which returns a series of cells of data from a
i have SOQL query which queries for some records based on a where condition.
I have a complicated query built up based on a users profile, I start

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.