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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:45:05+00:00 2026-05-24T08:45:05+00:00

I’m retrieving my data for part of my site with a typical MySQL query

  • 0

I’m retrieving my data for part of my site with a typical MySQL query and echoing out the results from various fields etc etc from my main table whose structure is not important but which has a unique id which is ‘job_id’

In order to have multiple catagories associated with that ‘job_id’ i have employed a toxi solution which associates catgories to each ‘job_id’.

TABLE `tags` (
`tag_id` INT NOT NULL AUTO_INCREMENT, 
`tag_name` VARCHAR(20) NOT NULL, 
PRIMARY KEY (`tag_id`)
)

CREATE TABLE `tag_relational` (
`job_id` INT NOT NULL, 
`tag_id` INT NOT NULL
)

What i want to do is, when i echo out the info from the main table (using ‘job_id’) i also want to echo all the catagories which that job_id is matched against.

The query below only returns the first catagory(tag_name) that the job_id is listed against, when it should be up to six (at the moment):

$query = "SELECT * FROM tags t
JOIN tag_relational r   
ON t.tag_id=r.tag_id
WHERE r.job_id = $job_id";

$result=mysql_query($query) or die(mysql_error());
$cats=mysql_fetch_assoc($result);

In my code i’m using this to echo out the matched catagories:

<?php echo $cats['tag_name'];?>

Can someone explain how i can get ALL the catagory names to echo out rather than just the first?
Thanks
Dan

BTW, apologies to mu is too short who kindly answered my question when i had dummy/less complete information above.

  • 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-24T08:45:07+00:00Added an answer on May 24, 2026 at 8:45 am

    If you just want to list the category names, then you could use group_concat sort of like this:

    select b.*,
           group_concat(c.category_name order by c.category_name separator ' ,') as cats
    from business b
    join tbl_works_categories w on b.id = w.bus_id
    join categories c on w.category_id = c.category_name
    where ...
    group by b.id
    

    You’d need a proper WHERE clause of course. That will give you the usual stuff from business and the category names as a comma delimited list in cats.

    If you need the category IDs as well, then two queries might be better: one to get the business information and a second to collect the categories:

    select w.bus_id, c.category_id, c.category_name
    from tbl_works_categories w
    join categories c
    where w.bus_id IN (X)
    

    where X is a comma delimited list of business ID values. Then you’d patch things up on the client side.

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

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
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 have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I've tracked down a weird MySQL problem to the two different ways I was
I have a text area in my form which accepts all possible characters from
I know there's a lot of other questions out there that deal with this
Does anyone know how can I replace this 2 symbol below from the string

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.