<b>Note you test the value of $tbdocument but don't display
anything from it. </b>
That's exactly right! What is happening here is three things. First, I look for all of the articles in the database that are Protocols (indicated by the fkSubSxn='11'). If any exist, then I print "Protocols:".
/ show Protocols first /
$Document_query = "select * from tbDocument where fkSubSxn='11'";
$Document_result = mysql_query($Document_query, $mysql_link);
$tbDocument = mysql_fetch_object($Document_result);
$pkDocument = $tbDocument->pkDocument;
if($tbDocument){
print "<tr>\n";
print "<td bgcolor=\"#c0c0c0\" valign=\"top\"><font face=\"verdana,sans-serif\" size=\"-2\">\n";
print "<b>Protocols</b>:<br>\n";
Then, for each document that has fxSubSxn equal to 11, I check to make sure that it is also related to the specific Product Group that I am displaying. For each document that is related to this product group, I print the title of the Document as a hyperlink to its proper location.
while($tbDocument = mysql_fetch_object($Document_result)){
$pkDocument = $tbDocument->pkDocument;
/ find related documents /
$DocumentLProdGrp_query = "select from tbDocumentLProdGrp where fkDocument='$pkDocument' && fkProdGrp='$pkProdGrp'";
$DocumentLProdGrp_result = mysql_query($DocumentLProdGrp_query, $mysql_link);
while($tbDocumentLProdGrp = mysql_fetch_object($DocumentLProdGrp_result)){
/ list the document /
$Title = stripslashes($tbDocument->Title);
$fkSubSxn = $tbDocument->fkSubSxn;
$fkTNVolume = $tbDocument->fkTNVolume;
$FileName = stripslashes($tbDocument->FileName);
/ fetch the subdirectory name /
$SubSxn_query = "select from tbSubSxn where pkSubSxn = '$fkSubSxn'";
$SubSxn_result = mysql_query($SubSxn_query, $mysql_link);
$tbSubSxn = mysql_fetch_object($SubSxn_result);
$SubDir = $tbSubSxn->SubDir;
print "<a href=\"../$SubDir/$FileName\">$Title</a>\n";
print "<p>\n";
}
}
However, this means that, even if there are no products where fkSubSxn=11 AND that are also related to this specific Product Group (fkProdGrp='pkProdGrp'), as long as there are some documents where fkSubSxn=11, it will print "Protocols:" even though there will be no listed Protocol documents. If I put the if statement INSIDE the loop that calls for related Product Groups, then it prints "Protocols:" for each document. I want it to print "Protocols:" only once and then list all related documents. Does that make more sense?
Thanks for your help!
Christiane