I am trying to get this code to work. I am getting a list of results from my database which are less than 30 days old. And displaying them in my div.
This works fine, however if there are no results I want to echo out No Recent Activity, and I am unable to get this bit to work. I am using a MySQL num row count and else statement to try and get it to do what I need but It won't show no recent activity even if there is no results.
Please can someone show me where I am going wrong.
thanks,
Code:
<div class="dashboard_stats">
<?php require_once 'config.php'; ?>
<?php
$table = 'recent_activity';
echo '<div class="dashboard_stats_heading"><table class="table_other"><tr><td>Description</td><td>Reference</u></td><td>Status</td><td>Supplier Name</td></tr></table></div>';
$query1 = "SELECT * FROM $table WHERE user_id = '{$_SESSION['id']}' AND date > NOW() - INTERVAL 30 DAY ORDER BY date DESC";
$result1 = mysql_query($query1);
while ($row1 = mysql_fetch_array($result1)) {
if(mysql_num_rows($result1)>0){
$date = $row1['date'];
require_once 'time_ago.php';
if($row1['activity_type']==='Bank'){
$activity_type = 'Bank Details Changed';
}else{
if($row1['activity_type']==='Username'){
$activity_type = 'Username Changed';
} else {
if($row1['activity_type']==='Password'){
$activity_type = 'Password Changed';
} else {
if($row1['activity_type']==='Contact'){
$activity_type = 'Contact Details Changed';
} else {
if($row1['activity_type']==='Invoice'){
$activity_type = 'Invoice Submitted';
} else {
if($row1['activity_type']==='Trading'){
$activity_type = 'Trading Suspended';
}
}
}
}
}
}
echo '<table><tr><td><p>'.$activity_type.'</p></td><td><p>1234</p></td><td><p>'.$row1['status'].'</p></td><td><p>';
echo pretty_relative_time($row1['date']);
echo '</p></td></tr><tr class="separator"></tr></table>';
}else{
echo '<div id="content">No Recent Activity</div>';
}
}
echo '</div>';
?>
</div>