![]() |
general php join question - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: general php join question (/showthread.php?tid=15147) |
general php join question - El Forum - 01-27-2009 [eluser]new_igniter[/eluser] Hello, I am wondering if someone can give me some pointers. I am working on a simple site that is unfortunately outside of CI, and is PHP. I have 2 tables, one with the main business name: CREATE TABLE `twibsDB` ( `twibsID` int(11) NOT NULL auto_increment, `twibName` varchar(255) NOT NULL, `createTime` timestamp NOT NULL default CURRENT_TIMESTAMP, PRIMARY KEY (`twibsID`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=2201 ; the other with tags associated with that business: CREATE TABLE `twibTags` ( `tagID` int(11) NOT NULL auto_increment, `tagText` varchar(300) NOT NULL, `twibsID` int(11) NOT NULL, `createTime` timestamp NOT NULL default CURRENT_TIMESTAMP, PRIMARY KEY (`tagID`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=5160 ; The tables are associated though `twibsID`, the primary AI key in the first table and there could be 10 or 12 tags associated with each business. How would I write the mysql query with a join statement so that I could get something back where I could loop through the businesses and if they had tags, loop through the array of tags? I have been doing a lot of experimenting, but nothing is working and I am just looking to learn here. Thanks so much!!!! general php join question - El Forum - 01-28-2009 [eluser]umefarooq[/eluser] hi you can do one thing if you have array of tags just implode the whole array with like this Code: $tags = implode(',',$tagArray) than use this query Code: select a.twibName from twibsDB as a inner join twibTags as b on a.twibsID = b.twibsID check it will work fine. |