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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:33:54+00:00 2026-06-11T15:33:54+00:00

So, I have this query in PHP which is working as intended: SELECT files.ID,

  • 0

So, I have this query in PHP which is working as intended:

SELECT files.ID, 
       files.Name,
       files.Downloads, 
       if (dlratings.userID IS NULL,0,r.vote) AS has_voted
FROM files
LEFT JOIN dlratings
   ON (files.ID = dlratings.fileID AND dlratings.userID = $userID)
WHERE files.Temporary != 1 AND files.Type = $type AND files.Cat_1 = $cat_1 
ORDER BY files.rating DESC, files.DateOrder DESC

Now comes my problem: I want to also select the tags with which these selected files are associated. I am using the toxi method, meaning I have a table called “tagmap” with the rows file_id and tag_id and I have the table “tags” with the rows tag_id and tag_name.

To list the tags I need on a page with only one File, I use this query:

SELECT files.Name,
       GROUP_CONCAT(tags.tag_name ORDER BY tags.tag_name SEPARATOR ', ') AS tags
FROM files
LEFT JOIN tagmap
   ON tagmap.file_id = files.ID
LEFT JOIN tags
   ON tagmap.tag_id = tags.tag_id
WHERE files.ID = $fileID

How do I combine the two, so I can show the tags in the list that is provided by the first query?

This is what I tried but it only gives me 1 result:

SELECT files.ID, 
       files.Name,
       files.Downloads,
       GROUP_CONCAT(tags.tag_name ORDER BY tags.tag_name SEPARATOR ', ') AS tags
       if (dlratings.userID IS NULL,0,r.vote) AS has_voted
FROM files
LEFT JOIN tagmap
   ON tagmap.file_id = files.ID
LEFT JOIN tags
   ON tagmap.tag_id = tags.tag_id
LEFT JOIN dlratings
   ON (files.ID = dlratings.fileID AND dlratings.userID = $userID)
WHERE files.Temporary != 1 AND files.Type = $type AND files.Cat_1 = $cat_1 
ORDER BY files.rating DESC, files.DateOrder DESC

Note that I am calling these querys via php and I use mysqli. I experimented a bit with the mysqli_multi_query but I am totally lost on that one too…

  • 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-11T15:33:54+00:00Added an answer on June 11, 2026 at 3:33 pm

    Try adding a GROUP BY files.ID. That might do it?

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

Sidebar

Related Questions

I have this working query that outputs URL and click counts from database. <?php
So i have this script: <?php $query = mysql_query( SELECT meetup AS text, id
I have this mysql query using PHP and first part is working fine, but
I am working in PHP. This is my query: $sql = SELECT * from
I have this PHP code to highlight the Query on search results. if (isset($_REQUEST['k'])){
Have this query: SELECT HOUR( DATE ) AS hr, COUNT( * ) AS cnt
I have this query... SELECT Distinct([TargetAttributeID]) FROM (SELECT distinct att1.intAttributeID as [TargetAttributeID] FROM AST_tblAttributes
I have this query which on executing in my sql command line client executes
i have this query: SELECT `completed`.`ID` AS `ID`,`completed`.`level` AS `level`,`completed`.`completed_in` AS `completed_in`, COUNT(1) AS
I have this query SELECT zip, ( 3959 * acos( cos( radians(34.12520) ) *

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.