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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:25:07+00:00 2026-06-14T06:25:07+00:00

I’ve got the three tables below from which I wish to get the following

  • 0

I’ve got the three tables below from which I wish to get the following selects:

1.) Select all items from collaboration and group them by group_id in group_members for a given user
This means that when the user logs in, (s)he will see all (and only) collaboration items belonging to the groups where he is group member.

2.) For each group_id, select all collaboration items.
This means that when a user selects any group (group_id) from 1 above, he’s going to see all the collaborationitems belonging to the selected group (group_id)

Constraints: Each user MUST be a group member. The userstable is there to supply firstnameand lastname of user.

This is what I tried for 1 to no avail!


    function OrderByGroup_id($username) {
      $data = array();
      $currenttime = time();
      $q = "
      SELECT *
      FROM collaboration
      INNER JOIN group_members ON collaboration.group_id = group_members.group_id
      INNER JOIN users ON users.username = group_members.username
      WHERE collaboration.parent_id IS NULL and collaboration.is_comment = 0 
      AND group_members.username = :user group by collaboration.group_id";
      $sq = $this->connection->prepare($q);
      $sq->execute(array(':user' => $username));
    while($row = $sq->fetch()) {
      $json = array();
      $json['title'] = $row['title'];
      $json['question'] = $row['content'];
      $json['firstname'] = $row['firstname'];
      $json['lastname'] = $row['lastname'];
      $json['timestamp'] = $row['timestamp'];
      $json['key'] = $row['group_id'];
      $data[] = $json;
     }
      $allposts =json_encode($data);
      return $allposts= json_decode($allposts, true);
    }

Here are the tables


CREATE TABLE IF NOT EXISTS `collaboration` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `parent_id` int(11) DEFAULT NULL,
  `group_id` varchar(255) DEFAULT NULL,
  `author` varchar(30) NOT NULL,
  `title` varchar(255) DEFAULT NULL,
  `content` text NOT NULL,
  `is_comment` tinyint(1) unsigned NOT NULL,
  `file` tinyint(1) unsigned NOT NULL DEFAULT '0',
  `points` int(11) DEFAULT NULL,
  `timestamp` int(11) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `users` (
  `firstname` varchar(30) NOT NULL,
  `lastname` varchar(30) NOT NULL,
  `username` varchar(30) NOT NULL,
  PRIMARY KEY (`username`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS `group_members` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `username` varchar(30) NOT NULL,
  `group_id` varchar(50) NOT NULL,
  `status` tinyint(1) unsigned NOT NULL,
  `timestamp` int(11) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8;

Thanks for your input!

  • 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-14T06:25:08+00:00Added an answer on June 14, 2026 at 6:25 am

    The following select does deliver the request for question 1. However, I know the query is not optimal because I do select entries that I don’t need at the moment. For example the use of *
    I would like to select only title, content, timestamp, group_id, from collaboration and firstname, lastname, from users

        
        SELECT * FROM collaboration
        INNER JOIN group_members ON collaboration.group_id = group_members.group_id
        INNER JOIN users ON users.username = collaboration.author
        WHERE collaboration.parent_id IS NULL and collaboration.is_comment = 0 
        AND group_members.username = :user 
        GROUP BY collaboration.group_id
        ORDER BY collaboration.timestamp DESC
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text area in my form which accepts all possible characters from
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm trying to select an H1 element which is the second-child in its group
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
Let's say I'm outputting a post title and in our database, it's Hello Y’all
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small

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.