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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:26:26+00:00 2026-05-24T09:26:26+00:00

I’m having a little trouble with a mysql_fetch_assoc script i hope you can help

  • 0

I’m having a little trouble with a mysql_fetch_assoc script i hope you can help with.

Background:
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
)

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, which id using:

$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:

<p>Job Catagories | <?php while ($cats=mysql_fetch_assoc($result)) { echo $cats['tag_name'];}?></p>

I have two problems:

  1. The above echo seems to be ignoring the first tag name all together, so if a job is tagged with six catagories, it only echos five. If a job is only tagged with one, I get nothing. The query works in the SQL shell, so I’m assuming the problem lie in the PHP.
  2. When I do get multiple echos, I want to be able to seperate them with a comma or a |, but I’m unfamiliar with using group_concat in queries, so I could also use a little help there.
  • 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-24T09:26:27+00:00Added an answer on May 24, 2026 at 9:26 am

    Because mysql_fetch_assoc is already called once before the while loop, the first row is always discarded.

    This should solve your problems:

    $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());
    
    <p>Job Catagories | 
    <?php 
    $first = true;
    while ($cats=mysql_fetch_assoc($result)) { 
        if($first){
            $first = false;
        } else{
            echo ", ";
        }
        echo $cats['tag_name'];
    }
    ?>
    </p>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I have a jquery bug and I've been looking for hours now, I can't
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
We're building an app, our first using Rails 3, and we're having to build
Does anyone know how can I replace this 2 symbol below from the string
I want to construct a data frame in an Rcpp function, but when I
I have some data like this: 1 2 3 4 5 9 2 6

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.