Page 1 of 1

join table??

Posted: Sun May 18, 2008 7:22 am
by kanchan
hi!!

is there any method to join 2 mysql tables..
i m thinking to make a gallery page and i think for the gallery i need to tables and it may need to join both tables....
is there any way to make simple gallery script with mysql backend?

Help me guys..... i am a simple php coder(not a professional)....
please......
i will be very grateful to you...

thanks in advance..

Re: join table??

Posted: Sun May 18, 2008 11:40 am
by savadi
i dont really understand your question

but

simple way to join 2 tables

table 1

Code: Select all

CREATE TABLE category (
category_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
category_name VARCHAR( 255 ) NOT NULL
) ENGINE = innodb;
table 2

Code: Select all

CREATE TABLE gallery (
image_id INT NOT NULL ,
category_id INT NOT NULL ,
image_desc VARCHAR( 255 ) NOT NULL ,
image_location VARCHAR( 255 ) NOT NULL
) ENGINE = innodb;
Joining 2 tables to get category name for each image

Code: Select all

SELECT g.image_id, g.image_desc, g.image_location, c.category_name 
FROM gallery as g, category as c 
WHERE c.category_id = g.category_id
You also can use INNER JOIN, LEFT JOIN, RIGHT JOIN sql syntax to join 2 tables
Please refer here for more info http://www.w3schools.com/sql/sql_join.asp

Re: join table??

Posted: Sun May 18, 2008 1:40 pm
by kanchan
yeah i am looking this kind of code :D

i think u can code this gallery i m looking for...

can you please submit the gallery code you got??

i will be very very grateful to you....