Hi!! I am trying to solve this problem but nothing works fine.
If the data is availabe in database, it is displayed.But if there is no data, a blank page is displayed and the message “Sorry No Records Found…” is not displayed.Can anyone help me??I have given the code below.
<?PHP
require 'include/connection.php';
$query=mysql_query("SELECT * FROM clientenquiry");
while($row=mysql_fetch_array($query))
{
if($row!=0)
{
$id=$row['id'];
echo "<tr>
<td>"; echo $row['name']; echo "</td>
<td><a href=enquiryview.php?a=$id>View</a></td>
<td><a href=enquiryedit.php?b=$id>Edit</a></td>
<td><a href=enquirydelete.php?c=$id>Delete</a></td>
</tr>";
}
if($row==0)
{
echo "Sorry No Records Found..";
}
}
?>
SpikeZ
November 30, 2010, 7:16am
2
You can use mysql_num_rows() to check how many results were returned from the query.
require 'include/connection.php';
$query=mysql_query("SELECT * FROM clientenquiry");
if(mysql_num_rows($query) > 0) {
while($row=mysql_fetch_array($query))
{
if($row!=0)
{
$id=$row['id'];
echo "<tr>
<td>"; echo $row['name']; echo "</td>
<td><a href=enquiryview.php?a=$id>View</a></td>
<td><a href=enquiryedit.php?b=$id>Edit</a></td>
<td><a href=enquirydelete.php?c=$id>Delete</a></td>
</tr>";
}
}
} else {
echo "Sorry No Records Found..";
}
Dibley
November 30, 2010, 8:14am
3
I also find it helpful to paste the sql query direct into the SQl and see the result.
SELECT * FROM clientenquiry
then see what it returns, if anything.