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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T13:35:52+00:00 2026-06-08T13:35:52+00:00

Hi friends i am listing topics in php which may be associated with multiple

  • 0

Hi friends i am listing topics in php which may be associated with multiple category

my db schema is

topics

topic_id
user_id
topic_name

category 

category_id
category_name


topic_category (for association)

tc_id
topic_id
category_id

topic_response // for results

tr_id
topic_id
response ( given in a form of 5 star rating so its in range of 1-5 always )
user_id

what i need to do is

1st ) list top ten topics based on responses ya it will be based on count of responses

i tried ->

select t.* ,count(tr.response) as votes from topics t , topic_response tr where t.topic_id=tr.topic_id group by tr.topic_id order by votes LIMIT 10

not working

2nd) user will be shown list of topic . he can choose the category in which he wants that can be multiple too.

for example

if he chooses category_id 1,2,3,4 then topics listed in this category will be listed.

i have tried to

select t.* from topics t ,topic_category tc where tc.topic_id = t.topic_id and category_id IN (1,3,2,4) 
// not able to get idea on this i would prefer if i could do this in subquery since i also need to check if the user has already responded to that question .

**3) in case if i get a query working suppose .

from php side i will be getting an array of category_id from select multiple dropdown
like array(1,2,3,4)

so i was thinking how will make this query accept category id

in form of category_id IN (1,3,2,4) in mysql query**

**can i directly pass an array like

category_id IN ($ids) where $ids is an array**

i am a newbie in mysql please help me
you help will be appreciated 🙂

  • 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-08T13:35:55+00:00Added an answer on June 8, 2026 at 1:35 pm

    For the first question:

    You have to use LEFT JOIN and match (response’s topic id row) to (topic’s id) then count(response’s topic id) and GROUP everything by (response’s topic id).

    for example:

    Responses Table = responses

    response_id

    topic_id

    response_message

    Topics Table = topics

    id

    title

    content

    The query is

    SELECT topics.title,topics.content,COUNT(responses.topic_id) AS count FROM topics
    LEFT JOIN responses ON topics.id = responses.topic_id GROUP BY count LIMIT 10

    For question 2:

    1. You can try using AND ( IN 1 OR 2 OR 3 OR 4
    2. You can try using BETWEEN 1 AND 4
    3. WHERE(category_id>=1&&category_id<=4)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Friends i'm using string builder for generating Passenger List in which i have used
Friends, I like to know using which version of Android SDK we can develop
Friends my php 5.2 codes am keeping my password like this echo '<br>'.base64_encode(mhash(MHASH_MD5,'test')); result
Friends, I am able to get XML file by sing bytes, perhaps which is
Friends i am making an application in which i am using Map Activity. Now
I am developing functionality for Listing email(those who shared) of my-friends(who ever is logged
friends. I have a page, on which users can add comments (users can enter
Is there a function in the Facebook.php library for getting friends of the user
Friends, I've one question to ask. Which one is the correct syntax in jquery
Friends i need to store more than 100 mb data which come in zip

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.