Jump to content

Recommended Posts

Got a question on how to display this query correctly with PHP.

 

SELECT papers.papid AS papid,papers.title AS title, keywords.keyword AS keyword
FROM papers,keywords
WHERE papers.topid = ?
AND keywords.topid = papers.topid

 

What I want to do here is only show the papid once, but this one papid may have multiple keywords that are found using this query.

 

How do I make it display multiple keywords, but only one papid? Is this the correct way to go about it?

 

Hi

 

You could just loop through the returned data in php, and only display the papid and title when they change.

 

Another option would be to group the returned rows by the papid and just concatenate all the key words.

 

SELECT papers.papid AS papid,papers.title AS title, GROUP_CONCAT(keywords.keyword) AS keyword
FROM papers,keywords
WHERE papers.topid = ?
AND keywords.topid = papers.topid
GROUP BY papers.papid

 

All the best

 

Keith

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.