By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,719 Members | 1,439 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,719 IT Pros & Developers. It's quick & easy.

Pulling out matching values from a database

P: 404
Hi, I'm using a mysql database to store information for the frontpage of my website,, I'm adding the tutorials right now, everything thing is going fine, but there is a problem that I forsaw, and lo and behold it happened. I'm one table called tutorials and storing the tutorials with one value being type, (example: photoshop, gimp, apophysis.) I want to use the type column to make a category page, the code I am using is this:

[PHP]$sql = mysql_query('SELECT `type` FROM `tutorials`') or die("Error: ".mysql_error());

while($info = mysql_fetch_array($sql)) {
echo ucfirst($info['type'])."<br />";

Since I have more than one of each type of tutorial (actually, right now, I have two of each) its printing out the type for each one, so I'm getting two photoshops, two gimps, and two apophysis'. Is there some code that I can use to only pull out each type once, even if it is in the type field more than once. My first thought was some comparison code, but I've not been doing PHP for long, so I don't really know how. Can anyone give me an easy way (or just any way, if there is no easy way, I'm not too picky) to do this please, I would be very grateful.

The reason that I have the type in there like this, instead of having each type in its own seperate table, is becuase I want to have someone be able to go to and it'll show all the different programs we have tutorials for, then if they go to, it'll show all the tutorials for photoshop, then they can go to and it'll show that tutorial. I know this is possible, and relatively simple, so can anyone help me?

Feb 10 '07 #1
Share this Question
Share on Google+
5 Replies

Expert 2.5K+
P: 4,258
Use the GROUP BY attribute as in:
Expand|Select|Wrap|Line Numbers
  1. SELECT type FROM tables GROUP BY type;
Ronald :cool:
Feb 11 '07 #2

P: 404
You are amazing, thank you.
Feb 11 '07 #3

P: 404
Sorry for the double post, but I have a further question.

I want to sort these further by category (I will change the current "type" to "program" and type will become the...type of tutorial, whether that be graphics, video, php, etc...

If I add an extra column to the table, called type (after changing current type to program), how will I sort them so that I can get an output like this:


Vegas 7

Is this possible?

Thank you in advance.
Feb 11 '07 #4

P: 404
Bump...anyone, please I need some help.
Feb 12 '07 #5

P: 404

I need some help folks, I tried to do this on my own but I can't find anything that works.
Feb 12 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.