When I am displaying ALL reports from the database and the pictures or Letters (NOTE: Query 2 & Query3) = 0 (or none) It does not display as 0 It will display whatever some other report ID (sort by reportid) shows for letters or pictures.
eg; mysql_num_rows($result2); and mysql_num_rows($result3); do not show as "0" when there are no pics or letters in the pictures or letters tables for this reportid.
Now if all reports have letters and pictures then it shows correctly. Below is the partial code pertanent to this..
$sort = "$reportid";
$query = "SELECT * FROM reports WHERE reportid = '$reportid' $sort LIMIT $start,$pagelimit";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result)) {
$count = mysql_num_rows($result);
$report_date = $row[report_date];
$thereportid = $row[reportid];
$query2 = "SELECT FROM pictures WHERE reportid = '$reportid'";
$result2 = mysql_query($query2);
while ($row5 = mysql_fetch_array($result2)) {
$k = mysql_num_rows($result2);
}
if ($k == ''){
$thepictures = "0";
} else{
$thepictures = "$k";
}
$query3 = "SELECT FROM letters WHERE reportid = '$reportid'";
$result3 = mysql_query($query3);
while ($row3 = mysql_fetch_array($result3)) {
$m = mysql_num_rows($result3);
}
if ($m == ''){
$theletters = "0";
} else{
$theletters = "$m";
}
$i++;
echo "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"599\">
<tr>
<td height=\"15\" width=\"599\" style=\"border: 1px solid rgb(0,0,0)\"><div align=\"center\"><center><table
border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"597\" height=\"0\">
<tr>
<td width=\"597\" height=\"2\"></td>
</tr>
<tr>
<td bgcolor=\"#E9E9E9\" width=\"597\" style=\"border-bottom: 1px solid rgb(0,0,0)\"><div
align=\"center\"><center><table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"591\">
<tr>
<td width=\"591\" height=\"10\"></td>
</tr>
<tr>
<td width=\"591\"><small><font face=\"Tahoma\"> REPORT DATE: <font
color=\"#004080\">$report_date </font><font color=\"#000000\">REPORT ID:</font><font color=\"#004080\"> $thereportid</font></font></small></td>
</tr>
<tr>
<td width=\"591\" height=\"5\"></td>
</tr>
</table>
</center></div></td>
</tr>
<tr>
<td width=\"597\" height=\"15\"></td>
</tr>";
echo "<tr>
<td width=\"597\"><p align=\"center\"><font face=\"Tahoma\"><small><strong>This
Report Has a Total of:</strong> <strong><font color=\"#FF0000\"> </font><font
color=\"#004080\">$thepictures</font></strong> Pictures <small><font color=\"#004080\">[</font><a
href=\"report_pics.php?reportid=$thereportid\" class=\"style3\">View
</a><font color=\"#004080\">]</font></small></font></strong> <font
color=\"#004080\" face=\"Tahoma\">and <strong>$theletters</strong></font><font
face=\"Tahoma\"> Letters/Emails <small><font color=\"#004080\">[</font><a
href=\"report_letters.php?reportid=$thereportid\" class=\"style3\">View
</a><font color=\"#004080\">]</font></small></font></small></td>
</tr>
</table>";
}
Can someone show me what I have wrong in the code.? Any help is greatly appreciatted..