join table??

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kanchan
Forum Commoner
Posts: 80
Joined: Tue Nov 30, 2004 12:03 pm

join table??

Post 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..
savadi
Forum Newbie
Posts: 4
Joined: Thu May 15, 2008 10:08 pm

Re: join table??

Post 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
kanchan
Forum Commoner
Posts: 80
Joined: Tue Nov 30, 2004 12:03 pm

Re: join table??

Post 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....
Post Reply