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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:55:44+00:00 2026-05-15T22:55:44+00:00

I have 4 Tables (listed bellow) and need: get last 10 Chats from Room

  • 0

I have 4 Tables (listed bellow) and need:

  1. get last 10 Chats from Room 3 without banned users
  2. show nickname for fromuserid
  3. HIDE Users $userid dont like to see table “HIDE”

Table 1 “chats”

ID(autoinc)   fromuserid   roomid   text
 1               23          3      bla
 2               14          1      bla
 3               11          3      bal

Table 2 “user” /shorted/

ID(autoinc)   nickname   banned
1             chris        0
2             paul         1     // 1 = banned

Table 3 “hide”

ID(autoinc)   orguser    hideuser
1             12          3
2             33          12

Right now i solved it with PHP Routine, but I have to go through EACH result and make always a new query, that needs too long;

  $userid = 1; // actual user

  // List all chats and show userid as nickname
  $sql_com = "SELECT user.id, user.nickname, chats.text, chats.id ".
        " FROM chats, user".
        " WHERE ".
        " chats.fromuserid = user.id ".
        " AND chats.roomid = 3 ".
        " AND user.banned != 1 ".
        " ORDER BY chats.id DESC";  
  $result = mysql_query ($sql_com);       

  $count = 0;
  while ($row = mysql_fetch_array($result, MYSQL_NUM)) 
   {
       $dontshow = false;

       // Filter : dont show users $userid dont like to see (table "hide")
       $sql_com2 = "SELECT id from hide WHERE ( (orguser = ".$userid.") AND (hideuser = ".$row[0].") ) ";

       if ($result2 = mysql_query ($sql_com2)) 
       {
          if (mysql_num_rows($result2) > 0) $dontshow = true;
       }      


       // Output     
       if ($dontshow == false)
       {
            $count++;
            echo "Nickname: ".$row[1]." Text: ".$row[2];
       }

       if ($count > 10) break;
}

Btw. I made already some improvments, so the actual question may not fit with all answers (thanks for your help till now)

Finaly its now just about to integrate the filter “dont show people listed in table “hide” for my actual user”.

  • 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-15T22:55:45+00:00Added an answer on May 15, 2026 at 10:55 pm

    I think you need something along these general lines. I’ve done it slightly different from your question. Instead of getting the top 10 then removing records. It gets the top 10 records which would not be hidden.

    SELECT c.ID, c.fromuserid, c.roomid, c.text, u.nickname
    FROM chats c
    JOIN user u ON c.fromuserid = u.id
    where c.roomid = 3 AND user.banned = 0
    AND NOT EXISTS(
                  SELECT * FROM hide h 
                  WHERE h.hideuser = c.fromuserid
                  AND orguser = $userid) 
    ORDER BY c.ID DESC
    LIMIT 0,10
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some tables listed in persistence.xml as: <persistence-unit name=myEntityManager transaction-type=RESOURCE_LOCAL> <provider>org.hibernate.ejb.HibernatePersistence</provider> <class>com.myPackage.someTable</class> <class>com.myPackage.tableOne</class>
I have an tableview which is loaded from a mutablearray as listed below. However
I have 3 tables listed below: Blog BlogArticle Article ---- ----------- ------- id id------blog_id
If I have two tables as listed below, The first which shows the Raw
I have 3000+ tables in my SQL 2008 database with names like listed below,
I have three of many tables in Oracle (10g) database as listed below. I'm
I need to grab a column called SymNumber from two different tables. Both are
How can i join tables using column value? I have three tables as listed
I have two tables listed below. When a field is updated on switches I
I have two tables users with columns: uid, name, mail, etc users_roles with columns:

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.