I have an IF statement inside of a WHILE. Basically the while is pulling all records w/ a predetermined tag. The IF is comparing the value and displaying the data accordingly.
I have an else at the end "no data to display".
Problem:
If data exists but does not meet the value comparison, "no data to display" is shown but it is shown the same # of times for each occurance (because it's in the while loop).
Question:
How can I just have it shown once?
Code:
$balance = 50;
$ck1 = mysql_query("select * from table1 where tagged = '1'");
$chk2 = mysql_num_rows($ck1);
if ($chk2 > 0) {
while ($ck3 = mysql_fetch_array($ck1)) {
$id=$ck3[id];
$ck4 = mysql_query("select SUM(payment) AS total from table2 where id = '$id'");
$ck5 = mysql_fetch_array($ck4);
$amt = $dqry['total'];
if ($amt >= $balance) {
DISPLAY DATA HERE
} else { print 'no data to display'; } }
Any suggestions on how to write this code better?