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

HaLo2FrEeEk
100+
P: 404
Hi, I'm using a mysql database to store information for the frontpage of my website, http://claninfectionist.com, 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 />";
}[/PHP]

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 http://claninfectionist.com/tutorials/ and it'll show all the different programs we have tutorials for, then if they go to http://claninfectionist.com/tutorials/?cat=photoshop, it'll show all the tutorials for photoshop, then they can go to http://claninfectionist.com/tutorial...tut=GrungeText and it'll show that tutorial. I know this is possible, and relatively simple, so can anyone help me?

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


ronverdonk
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

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

HaLo2FrEeEk
100+
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:

Graphics:
Apophysis
Gimp
Photoshop

Video:
Vegas 7

Is this possible?

Thank you in advance.
Feb 11 '07 #4

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

HaLo2FrEeEk
100+
P: 404
Please!

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.