JOIN 3 tables, 1 having many rows with same ID. I need to show all comments related to each ID
up vote
0
down vote
favorite
My JOIN below - 3 tables - Database structure straight forward . problem table #3 comment_id = primary AI, company_id indexed (used for join), other fields non indexed. Core problem = rows with same ID.
$stmt_E = $db2->prepare("
SELECT c.company_id
, c.company_name
, c.company_status
, c.effective_date
, c.ckby
, c.time
, e.ck1
, e.ckby1
, e.time1
, e.ck2
, e.ckby2
, e.time2
, e.ck3
, e.ckby3
, e.time3
, e.ck4
, e.ckby4
, e.time4
, e.ck5
, e.ckby5
, e.time5
, e.ck6
, e.ckby6
, e.time6
, e.ck7
, e.ckby7
, e.time7
, e.ck8
, e.ckby8
, e.time8
, e.ck9
, e.ckby9
, e.time9
, e.ck10
, e.ckby10
, e.time10
, cc.company_id
, cc.active_comment
, cc.active_comment_sentby
, cc.active_comment_time
FROM companies c
JOIN enrolled_checklist e
ON e.company_id = c.company_id
JOIN active_comments cc
ON cc.company_id = c.company_id
WHERE company_status = 'E'
ORDER
BY company_name asc
");
$stmt_E->bind_result($company_id, $company_name,$company_status,$effective_date,$ckby,$time,$eck1,$eckby1,$etime1,$eck2,$eckby2,$etime2,$eck3,$eckby3,$etime3,
$eck4,$eckby4,$etime4,$eck5,$eckby5,$etime5,$eck6,$eckby6,$etime6,$eck7,$eckby7,$etime7,$eck8,$eckby8,$etime8,
$eck9,$eckby9,$etime9,$eck10,$eckby10,$etime10,$cccompany_id,$active_comment,$active_comment_sentby,$active_comment_time );
$stmt_E->execute();
$stmt_E->store_result();
My Loop - echo HTML - THIS SECTION gets duplicated by the same number of comments in 3rd table rather than the actual comments populating in desired section
while ($stmt_E->fetch()){
echo"
$tr
<td width='25%'> etc...............
I use 2 table info for checklist --- works perfect
When I try to place comment, matched to corresponding company, problems begin.
<div class='col-xs-12 cl-sm-12 col-md-12 col-lg-12'>
<input type='textarea' name='active_comment' value='$active_comment -$cccompany_id' placeholder='' readonly>
</div>
";
}
?>
I simply need all Comments from 3rd table to populate without duplicating all other fields. there could be as many as 25 Comments to one company ID. I need them to display within each company's section.
php mysql loops join
New contributor
kmbroker is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
up vote
0
down vote
favorite
My JOIN below - 3 tables - Database structure straight forward . problem table #3 comment_id = primary AI, company_id indexed (used for join), other fields non indexed. Core problem = rows with same ID.
$stmt_E = $db2->prepare("
SELECT c.company_id
, c.company_name
, c.company_status
, c.effective_date
, c.ckby
, c.time
, e.ck1
, e.ckby1
, e.time1
, e.ck2
, e.ckby2
, e.time2
, e.ck3
, e.ckby3
, e.time3
, e.ck4
, e.ckby4
, e.time4
, e.ck5
, e.ckby5
, e.time5
, e.ck6
, e.ckby6
, e.time6
, e.ck7
, e.ckby7
, e.time7
, e.ck8
, e.ckby8
, e.time8
, e.ck9
, e.ckby9
, e.time9
, e.ck10
, e.ckby10
, e.time10
, cc.company_id
, cc.active_comment
, cc.active_comment_sentby
, cc.active_comment_time
FROM companies c
JOIN enrolled_checklist e
ON e.company_id = c.company_id
JOIN active_comments cc
ON cc.company_id = c.company_id
WHERE company_status = 'E'
ORDER
BY company_name asc
");
$stmt_E->bind_result($company_id, $company_name,$company_status,$effective_date,$ckby,$time,$eck1,$eckby1,$etime1,$eck2,$eckby2,$etime2,$eck3,$eckby3,$etime3,
$eck4,$eckby4,$etime4,$eck5,$eckby5,$etime5,$eck6,$eckby6,$etime6,$eck7,$eckby7,$etime7,$eck8,$eckby8,$etime8,
$eck9,$eckby9,$etime9,$eck10,$eckby10,$etime10,$cccompany_id,$active_comment,$active_comment_sentby,$active_comment_time );
$stmt_E->execute();
$stmt_E->store_result();
My Loop - echo HTML - THIS SECTION gets duplicated by the same number of comments in 3rd table rather than the actual comments populating in desired section
while ($stmt_E->fetch()){
echo"
$tr
<td width='25%'> etc...............
I use 2 table info for checklist --- works perfect
When I try to place comment, matched to corresponding company, problems begin.
<div class='col-xs-12 cl-sm-12 col-md-12 col-lg-12'>
<input type='textarea' name='active_comment' value='$active_comment -$cccompany_id' placeholder='' readonly>
</div>
";
}
?>
I simply need all Comments from 3rd table to populate without duplicating all other fields. there could be as many as 25 Comments to one company ID. I need them to display within each company's section.
php mysql loops join
New contributor
kmbroker is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
2
This kind of problem is symptomatic of poor design. Any time you find yourself with enumerated columns (above,say, 2), alarm bells should start ringing
– Strawberry
yesterday
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
My JOIN below - 3 tables - Database structure straight forward . problem table #3 comment_id = primary AI, company_id indexed (used for join), other fields non indexed. Core problem = rows with same ID.
$stmt_E = $db2->prepare("
SELECT c.company_id
, c.company_name
, c.company_status
, c.effective_date
, c.ckby
, c.time
, e.ck1
, e.ckby1
, e.time1
, e.ck2
, e.ckby2
, e.time2
, e.ck3
, e.ckby3
, e.time3
, e.ck4
, e.ckby4
, e.time4
, e.ck5
, e.ckby5
, e.time5
, e.ck6
, e.ckby6
, e.time6
, e.ck7
, e.ckby7
, e.time7
, e.ck8
, e.ckby8
, e.time8
, e.ck9
, e.ckby9
, e.time9
, e.ck10
, e.ckby10
, e.time10
, cc.company_id
, cc.active_comment
, cc.active_comment_sentby
, cc.active_comment_time
FROM companies c
JOIN enrolled_checklist e
ON e.company_id = c.company_id
JOIN active_comments cc
ON cc.company_id = c.company_id
WHERE company_status = 'E'
ORDER
BY company_name asc
");
$stmt_E->bind_result($company_id, $company_name,$company_status,$effective_date,$ckby,$time,$eck1,$eckby1,$etime1,$eck2,$eckby2,$etime2,$eck3,$eckby3,$etime3,
$eck4,$eckby4,$etime4,$eck5,$eckby5,$etime5,$eck6,$eckby6,$etime6,$eck7,$eckby7,$etime7,$eck8,$eckby8,$etime8,
$eck9,$eckby9,$etime9,$eck10,$eckby10,$etime10,$cccompany_id,$active_comment,$active_comment_sentby,$active_comment_time );
$stmt_E->execute();
$stmt_E->store_result();
My Loop - echo HTML - THIS SECTION gets duplicated by the same number of comments in 3rd table rather than the actual comments populating in desired section
while ($stmt_E->fetch()){
echo"
$tr
<td width='25%'> etc...............
I use 2 table info for checklist --- works perfect
When I try to place comment, matched to corresponding company, problems begin.
<div class='col-xs-12 cl-sm-12 col-md-12 col-lg-12'>
<input type='textarea' name='active_comment' value='$active_comment -$cccompany_id' placeholder='' readonly>
</div>
";
}
?>
I simply need all Comments from 3rd table to populate without duplicating all other fields. there could be as many as 25 Comments to one company ID. I need them to display within each company's section.
php mysql loops join
New contributor
kmbroker is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
My JOIN below - 3 tables - Database structure straight forward . problem table #3 comment_id = primary AI, company_id indexed (used for join), other fields non indexed. Core problem = rows with same ID.
$stmt_E = $db2->prepare("
SELECT c.company_id
, c.company_name
, c.company_status
, c.effective_date
, c.ckby
, c.time
, e.ck1
, e.ckby1
, e.time1
, e.ck2
, e.ckby2
, e.time2
, e.ck3
, e.ckby3
, e.time3
, e.ck4
, e.ckby4
, e.time4
, e.ck5
, e.ckby5
, e.time5
, e.ck6
, e.ckby6
, e.time6
, e.ck7
, e.ckby7
, e.time7
, e.ck8
, e.ckby8
, e.time8
, e.ck9
, e.ckby9
, e.time9
, e.ck10
, e.ckby10
, e.time10
, cc.company_id
, cc.active_comment
, cc.active_comment_sentby
, cc.active_comment_time
FROM companies c
JOIN enrolled_checklist e
ON e.company_id = c.company_id
JOIN active_comments cc
ON cc.company_id = c.company_id
WHERE company_status = 'E'
ORDER
BY company_name asc
");
$stmt_E->bind_result($company_id, $company_name,$company_status,$effective_date,$ckby,$time,$eck1,$eckby1,$etime1,$eck2,$eckby2,$etime2,$eck3,$eckby3,$etime3,
$eck4,$eckby4,$etime4,$eck5,$eckby5,$etime5,$eck6,$eckby6,$etime6,$eck7,$eckby7,$etime7,$eck8,$eckby8,$etime8,
$eck9,$eckby9,$etime9,$eck10,$eckby10,$etime10,$cccompany_id,$active_comment,$active_comment_sentby,$active_comment_time );
$stmt_E->execute();
$stmt_E->store_result();
My Loop - echo HTML - THIS SECTION gets duplicated by the same number of comments in 3rd table rather than the actual comments populating in desired section
while ($stmt_E->fetch()){
echo"
$tr
<td width='25%'> etc...............
I use 2 table info for checklist --- works perfect
When I try to place comment, matched to corresponding company, problems begin.
<div class='col-xs-12 cl-sm-12 col-md-12 col-lg-12'>
<input type='textarea' name='active_comment' value='$active_comment -$cccompany_id' placeholder='' readonly>
</div>
";
}
?>
I simply need all Comments from 3rd table to populate without duplicating all other fields. there could be as many as 25 Comments to one company ID. I need them to display within each company's section.
php mysql loops join
php mysql loops join
New contributor
kmbroker is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
kmbroker is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited yesterday
Strawberry
25.6k83149
25.6k83149
New contributor
kmbroker is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked yesterday
kmbroker
11
11
New contributor
kmbroker is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
kmbroker is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
kmbroker is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
2
This kind of problem is symptomatic of poor design. Any time you find yourself with enumerated columns (above,say, 2), alarm bells should start ringing
– Strawberry
yesterday
add a comment |
2
This kind of problem is symptomatic of poor design. Any time you find yourself with enumerated columns (above,say, 2), alarm bells should start ringing
– Strawberry
yesterday
2
2
This kind of problem is symptomatic of poor design. Any time you find yourself with enumerated columns (above,say, 2), alarm bells should start ringing
– Strawberry
yesterday
This kind of problem is symptomatic of poor design. Any time you find yourself with enumerated columns (above,say, 2), alarm bells should start ringing
– Strawberry
yesterday
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
kmbroker is a new contributor. Be nice, and check out our Code of Conduct.
kmbroker is a new contributor. Be nice, and check out our Code of Conduct.
kmbroker is a new contributor. Be nice, and check out our Code of Conduct.
kmbroker is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53349303%2fjoin-3-tables-1-having-many-rows-with-same-id-i-need-to-show-all-comments-rela%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
This kind of problem is symptomatic of poor design. Any time you find yourself with enumerated columns (above,say, 2), alarm bells should start ringing
– Strawberry
yesterday