how to join Between four tables on mysql -


i have 4 tables mysql database, how join between them

users:

userid|username    1  | mark    2  | jon 

awards_user :

awardid|userid  1     |1      2     |2     

cat :

catid|catname    1 | english    2 | computer 

awards :

awardid|catid|awardname|awardlink  1     |1    |best1    |pic link  2     |2    |best2    |pic link 

resulte :

userid|username|catid|catname|awardid|awardname|awardlink

okay , try :

works shows 1 result, when there member holds award ، want show awards, if there no 1 holds them .

$all_awards = $db->query_read(" select * " . table_prefix . " users,awards_user,cat,awards  awards_user.awardid = awards.awardid  , awards_user.userid = users.userid  , awards.catid = cat.catid  ");   create table `awards` (   `id` int(10) unsigned not null auto_increment,   `forumid` int(10) unsigned not null,   `name` varchar(100) not null default '',   `link` varchar(100) not null default '',   primary key  (`id`) ) engine=myisam  default charset=utf8 auto_increment=2 ;  --  -- dumping data table `awards` --   insert `awards` values (1, 2, 'award one', 'http://www.mwadah.com/pict/noway9.gif'); insert `awards` values (2, 1, 'award 2', 'http://www.forum-ksa.com/up/uploads/images/forum-ksac59a7122d1.gif');  -- --------------------------------------------------------  --  -- table structure table `awards_user` --   create table `awards_user` (   `id` int(10) unsigned not null auto_increment,   `awardid` int(10) unsigned not null,   `userid` int(10) unsigned not null,   primary key  (`id`) ) engine=myisam  default charset=utf8 auto_increment=3 ;  --  -- dumping data table `awards_user` --   insert `awards_user` values (2, 2, 2);  -- --------------------------------------------------------  --  -- table structure table `forum` --   create table `forum` (   `forumid` smallint(5) unsigned not null auto_increment,   `title` varchar(100) not null default '',   primary key  (`forumid`) ) engine=myisam  default charset=utf8 auto_increment=2;  --  -- dumping data table `forum` --   insert `forum` values (1,'main category'); insert `forum` values (2,'main forum'); -- --------------------------------------------------------  --  -- table structure table `user` --   create table `user` (   `userid` int(10) unsigned not null auto_increment,   `username` varchar(100) not null default '' ) engine=myisam  default charset=utf8 auto_increment=3 ;  --  -- dumping data table `user` --   insert `user` values (1,'admin'); insert `user` values (1,'mark'); 

you structure join query this:

select * users join awards_user using(userid) join awards using(awardid) join cat using(catid) 

then can add where clause filter result.


Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -