Jump to content


Linking my tables....

  • Please log in to reply
1 reply to this topic

#1 romio

  • Members
  • PipPip
  • Member
  • 28 posts

Posted 03 March 2006 - 12:33 PM

well am a bit confused, my database should include many categories and each category could have one or more product, i have designed both of my tables, but how will i proceed now, how do i join them....

CREATE TABLE categories
                 categoryID int(11) NOT NULL auto_increment RIMARY KEY,  
                 name varchar(255) default NULL,              
                 parent int(11) default NULL,                 
                 products_count int(11) default NULL,         
                 description text,                            
                 picture varchar(30) default NULL,            
                 products_count_admin int(11) default NULL
CREATE TABLE products 
               productID int(11) NOT NULL auto_increment PRIMARY KEY,    
               categoryID int(11) default NULL,              
               name varchar(255) default NULL,               
               description text,                             
               customers_rating float NOT NULL default '0',  
               Price float default NULL,                     
               picture varchar(30) default NULL,             
               in_stock int(11) default NULL,                
               thumbnail varchar(30) default NULL,
               items_sold int(11) NOT NULL default '0',      
               big_picture varchar(30) default NULL,         
               enabled int(11) NOT NULL default '0',         
               brief_description text,                       
               list_price float default NULL,                
               product_code varchar(25) default NULL                    

#2 Barand

  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 03 March 2006 - 07:22 PM

Something like this

SELECT c.name, p.productID, p.name, p.description, p.price
FROM products p
INNER JOIN categories c ON p.categoryID = c.categoryID
ORDER BY c.name, p.name

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received


|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users