Hey folks,
Today I'm after a solution for a pretty simple problem, however, too hard for me to solve. I've got a MySQL query that reveals a table output. But if there is no result it is displaiing my table heads instead of the "else" message. The code is as follows, maybe someone could help. Cheers, Frank
[PHP]
$result = mysql_query("SE LECT var_01, var_02, var_03, var_04 var_05 FROM table WHERE var_01 = '$_POST[a]' AND var_02 = '$_POST[b]'
AND var_03 = '$_POST[c]'
ORDER BY var_01");
if ($result)
{
echo "<table border='1'>
<tr>
<th>var1</th>
<th>var2</th>
<th>var3</th>
<th>var4</th>
</tr>";
while($row = mysql_fetch_arr ay($result))
{
echo "<tr>";
echo "<td>" . $row['var_01'] . "</td>";
echo "<td>" . $row['var_02'] . "</td>";
echo "<td>" . $row['var_03'] . "</td>";
echo "<td>" . $row['var_04'] . "</td>";
echo "</tr>";
}
echo "</table>";mysql_c lose($con);
}else {
print "<h2>Sorry, no entries available!</h2>";
}
[/PHP]
The script works fine if there is a result. But if there is no result it gives me the table head instead of the error message.
Today I'm after a solution for a pretty simple problem, however, too hard for me to solve. I've got a MySQL query that reveals a table output. But if there is no result it is displaiing my table heads instead of the "else" message. The code is as follows, maybe someone could help. Cheers, Frank
[PHP]
$result = mysql_query("SE LECT var_01, var_02, var_03, var_04 var_05 FROM table WHERE var_01 = '$_POST[a]' AND var_02 = '$_POST[b]'
AND var_03 = '$_POST[c]'
ORDER BY var_01");
if ($result)
{
echo "<table border='1'>
<tr>
<th>var1</th>
<th>var2</th>
<th>var3</th>
<th>var4</th>
</tr>";
while($row = mysql_fetch_arr ay($result))
{
echo "<tr>";
echo "<td>" . $row['var_01'] . "</td>";
echo "<td>" . $row['var_02'] . "</td>";
echo "<td>" . $row['var_03'] . "</td>";
echo "<td>" . $row['var_04'] . "</td>";
echo "</tr>";
}
echo "</table>";mysql_c lose($con);
}else {
print "<h2>Sorry, no entries available!</h2>";
}
[/PHP]
The script works fine if there is a result. But if there is no result it gives me the table head instead of the error message.
Comment