Stop the loop! Ah! (a real brainteaser)

wxdqz

New Member
In this code, if there are no "Protocols", it still prints out "Protocols:". How do I get it to print out "Protocols:" once and only once so that it looks like

Protocols:
First Protocol
Second Protocol
Third Protocol

Here is the code:
/* 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";
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=http://www.phpbuilder.com/board/archive/index.php/\"../$SubDir/$FileName\">$Title</a>\n";
print "<p>\n";
}
}
print "</font></td>\n";
print "</tr>\n";
}
 
Back
Top