kickassamd Posted January 1, 2007 Share Posted January 1, 2007 I have 3 tables that i need to pull data out off in 1 query "i hope"ss_servers, ss_groups, ss_servicesFirst I need to select all groups from db then select all servers that match each group then select each service that matches each server so that i can output it to HTML like thisgroup 1 Server 1 Service 1group 2 Server 2 Service 2And hopefully it can still output likegroup 3 Server 3 Service 3 Server 4 Service 4 Service 4Thanks!! Quote Link to comment https://forums.phpfreaks.com/topic/32427-php-mysql-help-joins/ Share on other sites More sharing options...
c4onastick Posted January 1, 2007 Share Posted January 1, 2007 Tell us what the tables look like. Do you have group id's in each table? Guessing at your layout I'd do something like this:[code]SELECT a.group AS group, b.server AS server, c.service AS serviceFROM ss_groups AS a, ss_servers AS b, ss_services AS cWHERE a.group_id = b.group_id AND b.server_id = c.server_id[/code]This is my guess for your layout:[code]ss_groups: group_id group_name group_blahss_servers: server_id group_id server_namess_services: service_id server_id service...[/code] Quote Link to comment https://forums.phpfreaks.com/topic/32427-php-mysql-help-joins/#findComment-150651 Share on other sites More sharing options...
kickassamd Posted January 1, 2007 Author Share Posted January 1, 2007 [code]CREATE TABLE `ss_groups` (`gpID` int(11) NOT NULL auto_increment,`gpName` varchar(50) NOT NULL,`gpDesc` text NOT NULL,primary key (`gpID`))Type=MyISAM;CREATE TABLE `ss_servers` (`ssID` int(11) NOT NULL auto_increment,`ssName` varchar(50) NOT NULL,`ssAddy` varchar(100) NOT NULL,`ssDesc` text NOT NULL,`ssGrp` int(11) NOT NULL,primary key (`ssID`))Type=MyISAM;CREATE TABLE `ss_services` (`svID` int(11) NOT NULL auto_increment,`svName` varchar(50) NOT NULL,`svPort` int(5) NOT NULL,`svDesc` text NOT NULL,`svBind` int(11) NOT NULL,primary key (`svID`))Type=MyISAM;[/code]ssGrp is the group the server is binded to, and svBind is the server that the service is binded to, feel free to do whatever to my code to help it out ;) Quote Link to comment https://forums.phpfreaks.com/topic/32427-php-mysql-help-joins/#findComment-150658 Share on other sites More sharing options...
kickassamd Posted January 1, 2007 Author Share Posted January 1, 2007 Tried yours and i get an error[quote]SELECT a.group AS group, b.server AS server, c.service AS service FROM xoops_ss_groups AS a, xoops_ss_servers AS b, xoops_ss_services AS c WHERE a.gpID = b.ssID AND b.ssID = c.svBindError number: 1064Error message: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'group, b.server AS server, c.service AS service FROM xoops_ss_groups AS a' at line 2[/quote] Quote Link to comment https://forums.phpfreaks.com/topic/32427-php-mysql-help-joins/#findComment-150660 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.