Forum FAQForum FAQSearchSearch MemberlistMemberlist Forum ignore listForum ignore list RegisterRegister ProfileProfile Log in to check your private messagesLog in to check your private messages Log inLog in
MySQL query

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    mi3dot.org Forum Index -> Server-side
View previous topic :: View next topic  
Author Message
PsychoPod



Joined: 05 Oct 2003
Posts: 166

PostPosted: 06.10.2006 11:03    Post subject: MySQL query Add user to your forum ignore list Reply with quote

Pozdrav, dugo sam vec na ovom forumu ali nisam previse postao u zadnjih godinu dana sigurno, ako ne i vise:) imam pitanje kako postaviti MySQL query u ovo situaciji.

imam 2 tablice
u jednoj tablici su proizvodi, u toj tablici imamo polje "kategorija" koje ima numericnu vrijednost kategorije.
druga tablica su kategorije i podkategorije(id, parent_id).
u tablici di su proizvodi u kategoije upisujem samo krajnju kategorije(podkategoriju). sada mi treba query u kojem bi ispisao proizvode po kategorijama(ne podkategorijama).
Code:
tablica 1
KATEGORIJE
-------------------------------
id | parent_id | ime kategorije
-------------------------------
primjer podataka.

1 | 0 | Torbe
2 | 0 | Majice
3 | 1 | Jeans
4 | 1 | Pamuk
5 | 2 | Kratke
6 | 2 | Duge


tablica 2

PROIZVODI
--------------------------
id | proizvod | kategorija
--------------------------
primjer podataka

1 | D&G traper | 3
2 | D&G new    | 5

(to bi bila znaci jedna jeans D&G torba i D&G kratka majica)

treba mi query da ispisem ako kliknem na link koji bi prikazao sve Torbe.
SELECT * FROM proizvodi WHERE kategorija = 1 ORDER BY autor DESC;
ovaj query ne bi dao nista jer je u proizvodima upisana podkategorija.

treba mi query koji bi mi ispisao sve torbe(bile one jeans ili pamuk) Smile

btw. ovaj primjer totalno nema veze s onim sto radim. samo logiku query-a nikako da slozim.
Back to top
View user's profile Send private message
retro_one



Joined: 16 Sep 2003
Posts: 880
Location: DUBRAVA.

PostPosted: 06.10.2006 11:13    Post subject: Add user to your forum ignore list Reply with quote

ti zelis ispisati sve proizvode u kategoriji, i sve proizvode u podkategorijama te kategorije, jel tako?

_________________
Just your average eccentric programmer.
Back to top
View user's profile Send private message
carr



Joined: 13 Nov 2003
Posts: 1397
Location: Karlovac

PostPosted: 06.10.2006 11:20    Post subject: Add user to your forum ignore list Reply with quote

ako sam dobro shvatio problem

Code:
SELECT *,categories2.category_id AS main_cat_id FROM items
JOIN categories ON categories.category_id=items.category
JOIN categories AS categories2 ON categories.parent_id=categories2.category_id
WHERE main_cat_id=1

dakle moras joinati tablicu samu na sebe, s tim sto joj dajes alias (as categories2) tako da to sljaka.

_________________
Bolje biti malo lud, nego malo pametan.
Back to top
View user's profile Send private message Visit poster's website
PsychoPod



Joined: 05 Oct 2003
Posts: 166

PostPosted: 06.10.2006 19:42    Post subject: Add user to your forum ignore list Reply with quote

maxy mi je lijepo poslao query tako da je to sredjeno, eto bas prije 5 min.

puno hvala na odg.

pozdrav
Back to top
View user's profile Send private message
Sulien



Joined: 04 Jan 2004
Posts: 2905
Location: Zagreb

PostPosted: 06.10.2006 19:51    Post subject: Add user to your forum ignore list Reply with quote

Maxy je živ? Smile
Back to top
View user's profile Send private message Send e-mail Visit poster's website
zvone



Joined: 09 Sep 2003
Posts: 160
Location: Zg

PostPosted: 06.10.2006 19:58    Post subject: Add user to your forum ignore list Reply with quote

Možeš postat taj sql query ?

_________________
Odin's descendant
Back to top
View user's profile Send private message
damir



Joined: 10 Jul 2004
Posts: 49

PostPosted: 06.10.2006 22:11    Post subject: Re: MySQL query Add user to your forum ignore list Reply with quote

PsychoPod wrote:

btw. ovaj primjer totalno nema veze s onim sto radim. samo logiku query-a nikako da slozim.



http://en.wikipedia.org/wiki/Relational_algebra

ako ti je to naporno nađi neki ORM pa ćeš slične probleme rješavati puno lakše npr.

Code:
SELECT *,categories2.category_id AS main_cat_id FROM items
JOIN categories ON categories.category_id=items.category
JOIN categories AS categories2 ON categories.parent_id=categories2.category_id
WHERE main_cat_id=1


postaje nešto kao

Code:
rez=kategorije(torbe).proizvodi.pamuk

_________________
pass the joint ...
Back to top
View user's profile Send private message Visit poster's website
unique



Joined: 29 Mar 2004
Posts: 655

PostPosted: 06.10.2006 22:28    Post subject: Add user to your forum ignore list Reply with quote

Sulien wrote:
Maxy je živ? Smile

Exclamation

_________________
Activate interlock! Dynotherms connected! Infracells up! Mega thrusters are go! LET'S GO VOLTRON FORCE!
Back to top
View user's profile Send private message
PsychoPod



Joined: 05 Oct 2003
Posts: 166

PostPosted: 08.10.2006 19:37    Post subject: Add user to your forum ignore list Reply with quote

ma dugo nisam radio kompleksnije query-e. tako da mi je logika posla naopako sada od faksa i svega. pomoc sam dobio i to je samo vazno:)

@damir - link je super.
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    mi3dot.org Forum Index -> Server-side All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group