Jump to content

MySQL query to have category appear once.


SauloA

Recommended Posts

I've been hitting my head against the wall trying to figure this out.  :facewall:

 

I have a video table and a video category table.  The tables are pretty much set up like the following:

 

video_tbl

------------

video_id

video_title

video_cat_id

 

video_cat_tbl

-----------------

video_cat_id

video_cat

 

I wrote this query and it works fine.

 

SELECT video_cat, video_title
FROM video_tbl, video_cat_tbl
WHERE video_cat_tbl.video_cat_id = video_tbl.video_cat_id

 

The only problem is that the category appears in every row, as it should.  I want it to appear only once.  Something like the following.

 

Video Category 1

--------------------

Video 1

Video 2

 

Video Category 2

---------------------

Video 3

Video 4

 

I'm trying to create a recordset that will display the videos under a certain category.  I was looking into using GROUP BY, DISTINCT, or JOIN in the SQL query but I can't figure out what to do.  I'd appreciate the help.

Link to comment
Share on other sites

This is a formatting issue, not a MySQL issue.

MySQL will always give you back a 2-dimensional (spreadsheet like) view of your data. So you need to use PHP (or another scripting language) to parse out the result into the view you want (3-dimensional).

Link to comment
Share on other sites

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.