I have the following code to generate part of a table:
It effectively generates 3 table cells containing data obtained from my sql table for each row in the sql table.
My problem is when a record doesn't exist in the table that has both personid = {$user_id[$k]} and paymentid = $payid it doesn't do the echo it just skips it sometimes leaving my table missing a set of 3 cells on a row.
What I want it to do is (in psuedo-php)
so basically if there is no row in the table where personid = {$user_id[$k]} and paymentid = $payid just echo a row of cells containing hyphens
PHP:
$result2 = mysql_query("SELECT * FROM userpayments WHERE personid = {$user_id[$k]} AND paymentid = $payid ORDER BY paymentid ASC");
while($row2 = mysql_fetch_array($result2))
{
echo "<td " . $style . ">" . $row2['payed'] . "</td><td " . $style . ">" . $row2['fs'] . "</td><td>" . $row2['topay'] . "</td>";
}
My problem is when a record doesn't exist in the table that has both personid = {$user_id[$k]} and paymentid = $payid it doesn't do the echo it just skips it sometimes leaving my table missing a set of 3 cells on a row.
What I want it to do is (in psuedo-php)
PHP:
if ($result2 exists)
{echo "<td " . $style . ">" . $row2['payed'] . "</td><td " . $style . ">" . $row2['fs'] . "</td><td>" . $row2['topay'] . "</td>";}
else
{echo "<td " . $style . ">" . "-" . "</td><td " . $style . ">" . "-" . "</td><td>" . "-" . "</td>";}