am working on reports and currently have a problem with how the output should be when and if the MySQL statement returns an empty result. i have two problems i.e 1) i need to use the WHILE statement to give all possible results when query is true. 2) i think an ELSE statement needs to be used to redirect me to another page if the result is false. Now i have noticed that WHILE and ELSE statements cannot be used together in that way. correct me if am wrong. again if am to use IF where there is WHILE, the output will be limited to only one record.
<html>
<head>
<title>Messages Received</title>
</head>
<body>
<h1 align="center">Messeges Received</h1>
<form id="form1" method="post" action="">
<div align="center">
<table width="700" border="1" >
<tr style="background:#093; color:#FFF; font-weight:bold">
<td width="150">Name</td>
<td width="180">Email/User_ID</td>
<td width="174">Subject</td>
<td width="168">Date Received</td>
</tr>
<?php
include("connect.php");
mysql_select_db("ceec", $con);
$query = "SELECT * FROM messeges ORDER BY date DESC";
$result=mysql_query($query);
while ($row=mysql_fetch_array($result)){
$id=$row['id'];
$date = date("D d M, Y", strtotime($row['date']));
echo '
<tr>
<td>'. $row["name"] .'</td>
<td>'. $row["email"] .'</td>
<td>'. $row["sub"] .'</td>
<td>'. $date .'</td>
</tr>';
}
else
{
header("Location: no_sms.php");
}
?>
</table>
</form>
</body>
</html>