Jump to content

PHP \ MySQL Help Joins???


kickassamd

Recommended Posts

I have 3 tables that i need to pull data out off in 1 query "i hope"

ss_servers, ss_groups, ss_services

First 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 this

group 1
    Server 1
          Service 1

group 2
    Server 2
        Service 2

And hopefully it can still output like

group 3
    Server 3
        Service 3
    Server 4
        Service 4
        Service 4

Thanks!!
Link to comment
https://forums.phpfreaks.com/topic/32427-php-mysql-help-joins/
Share on other sites

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 service
FROM
ss_groups AS a,
ss_servers AS b,
ss_services AS c
WHERE
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_blah
ss_servers:
  server_id
  group_id
  server_name
ss_services:
  service_id
  server_id
  service
...[/code]
Link to comment
https://forums.phpfreaks.com/topic/32427-php-mysql-help-joins/#findComment-150651
Share on other sites

[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 ;)
Link to comment
https://forums.phpfreaks.com/topic/32427-php-mysql-help-joins/#findComment-150658
Share on other sites

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.svBind
Error number: 1064
Error 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]
Link to comment
https://forums.phpfreaks.com/topic/32427-php-mysql-help-joins/#findComment-150660
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.