Closed Thread Icon

Topic awaiting preservation: select only one register from different fields (Page 1 of 1) Pages that link to <a href="http://ozoneasylum.com/backlink?for=12392" title="Pages that link to Topic awaiting preservation: select only one register from different fields (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: select only one register from different fields <span class="small">(Page 1 of 1)</span>\

 
Wakkos
Maniac (V) Mad Scientist

From: Azylum's Secret Lab
Insane since: Oct 2000

posted posted 08-30-2002 12:15

Hello, I've been thinking about this but i don't find a way to do it
I want to select only one register from different fields.

Humm, hard to explain:

I'm making a photogallery, and the pics are ordered by cathegory, in the main page I want to show one pic from each cathegory.

I have the database like this:

Table name: table_img:
Fields: big_image, thumbnail, description, category

Table name: table_cat
Fileds: Cat_name, Description

How can I select one pic from each cathegory?

lallous
Paranoid (IV) Inmate

From: Lebanon
Insane since: May 2001

posted posted 08-30-2002 12:44

very nice question!

I don't know how to do that or if it is even possible!

but you know that you can easily do it programmatically (in PHP, ASP, whatever SSS lang.), right?


Wakkos
Maniac (V) Mad Scientist

From: Azylum's Secret Lab
Insane since: Oct 2000

posted posted 08-30-2002 12:52

Nop, I dunno!!!!

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 08-30-2002 12:56

Use "GROUP BY" SQL statement in your SELECT query...
http://www.mysql.com/doc/en/SELECT.html


lallous
Paranoid (IV) Inmate

From: Lebanon
Insane since: May 2001

posted posted 08-30-2002 16:25

Okay, Wakkos, mr.Max gave us a hint:

quote:
Table name: table_img:
Fields: big_image, thumbnail, description, category

Table name: table_cat
Fileds: Cat_name, Description



my query goes like:

code:
select 
table_img.thumbnail, table_img.description,
table_cat.cat_name as CategoryName
where
table_img.category = table_cat.cat_name
group by
table_cat.cat_name



you will have as many rows as you've got categories.

good luck.

Wakkos
Maniac (V) Mad Scientist

From: Azylum's Secret Lab
Insane since: Oct 2000

posted posted 09-01-2002 22:50



I've been working on this, I got to this, but it prints 5 registers and it does not matter the cathegory!
I would like to be one from cathegory and I have played with this a lot! but, Jheez.....

Here's the code, if any have a little of time to take a look at it, thanks a lot!!!

code:
$query_select = "select wakk_gallery.imagen, wakk_gallery_cat.categoria FROM wakk_gallery,wakk_gallery_cat WHERE wakk_gallery.categoria = wakk_gallery_cat.categoria LIMIT 5";

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 09-02-2002 09:03

Wakkos, you didn't use GROUP BY SQL statement like I suggested in my post from above (and that's why your query doesn't work correctly)...


Wakkos
Maniac (V) Mad Scientist

From: Azylum's Secret Lab
Insane since: Oct 2000

posted posted 09-02-2002 10:06

Done!!

I made it with the Group by, but when i was selecting the table to group by, it was not the table, it must be a column of a table..

I got it now:

(very close to lallous code)

code:
$query_select = "select wakk_gallery.imagen, wakk_gallery_cat.categoria FROM wakk_gallery,wakk_gallery_cat WHERE wakk_gallery.categoria = wakk_gallery_cat.categoria group by wakk_gallery_cat.categoria";



Thank you both, guys!

« BackwardsOnwards »

Show Forum Drop Down Menu