Jump to content

Query from 3 tables


web_master

Recommended Posts

Hi,

 

I got a problem, and I will try explain what I want on a simpliest way as I can.

 

So, I got 3 tables.

 

1. Group

2. "Under" group

3. Basic text

 

Well, the "Group" table cols is looks (simplified) like this:

ID

GroupName

 

The "UnderGroup" table cols is looks (simplified) like this:

ID

UnderGroupName

 

The "BasicText" table cols is looks (simplified) like this:

ID

Txt_Group_ID

Txt_UnderGroup_ID

Txt

 

I want to reload text to look like this:

 

I. GROUP NAME

- Undergroup

1. txt

2. txt

3. txt

...

 

II. GROUP NAME

- Undergroup

1. txt

2. txt

3. txt

...

 

Uh, I hope it is understable...

 

Thanx in advanced

 

T

 

Link to comment
https://forums.phpfreaks.com/topic/208822-query-from-3-tables/
Share on other sites

I try this... but its not good...

// Reload from dBase
$QueryReturn2 = mysql_query( 'SELECT
`refgroup`.`refgroup_id`,
`refgroup`.`refgroup_name_sr`,
`references`.`references_group`,
`references`.`references_id`,
`references`.`references_txt_sr`,
`refpodgroup`.`refpodgroup_id`,
`refpodgroup`.`refpodgroup_name_sr`,
`references`.`references_podgroup`
FROM
`references`
Inner Join refgroup ON refgroup.refgroup_id = `references`.references_group
Inner Join refpodgroup ON refpodgroup.refpodgroup_id = `references`.references_podgroup
GROUP BY `references`.`references_group`
ORDER BY `refgroup_id` ASC
');

// Check query
if(!$QueryReturn2) { echo mysql_error(); exit; }

// Request query
while($REQUEST = mysql_fetch_array ($QueryReturn2)) {
echo 'GRUPA ' . $REQUEST['refgroup_name_sr'] . '<br />';
echo '- ' . $REQUEST['refpodgroup_name_sr'] . '<br />';
echo $REQUEST['references_txt_sr'] . '<br />';
}

 

Its show me:

 

I GROUP (refgroup)

- Undergroup (refpodgroup)

1. Txt (references)

 

II GROUP (refgroup)

- Undergroup II (refpodgroup)

1. Txt (references)

 

There is a more than One "references" that belong to "refpodgroup" and "refgroup"

 

So I want to looks like this

 

I GROUP (refgroup)

- Undergroup (refpodgroup)

1. Txt (references)

2. Txt (references)

3. Txt (references) ...

 

II GROUP (refgroup)

- Undergroup II (refpodgroup)

1. Txt (references)

2. Txt (references)

3. Txt (references)...

Link to comment
https://forums.phpfreaks.com/topic/208822-query-from-3-tables/#findComment-1090908
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.