Copy link to clipboard
Copied
Hello All,
Please I need help on how to display a message on my search page if no record was found in a query. I have written my query thus:
$colsdate_rsPCODE = "-1";
if (isset($_GET['sdate'])) {
$colsdate_rsPCODE = $_GET['sdate'];
}
$coledate_rsPCODE = "-1";
if (isset($_GET['edate'])) {
$coledate_rsPCODE = $_GET['edate'];
}
$coltaxidn_rsPCODE = "-1";
if (isset($_GET['taxidn'])) {
$coltaxidn_rsPCODE = $_GET['taxidn'];
}
mysql_select_db($database_CRIRS_DB, $CRIRS_DB);
$query_rsPCODE = sprintf("SELECT pmtid, fullname, revca, revite, prefno, amnt AS Amount, code, paymthd, bankname, DATE_FORMAT(pdate, '%%d-%%M-%%Y' ) AS PDate FROM payments WHERE (code LIKE '%%401%%' OR code LIKE '%%104%%') AND pdate >= %s AND pdate <= %s AND taxidno = %s ORDER BY pdate desc", GetSQLValueString($colsdate_rsPCODE, "date"),GetSQLValueString($coledate_rsPCODE, "date"),GetSQLValueString($coltaxidno_rsPCODE, "text"));
$query_limit_rsPCODE = sprintf("%s LIMIT %d, %d", $query_rsPCODE, $startRow_rsPCODE, $maxRows_rsPCODE);
$rsPCODE = mysql_query($query_limit_rsPCODE, $CRIRS_DB) or die(mysql_error());
$row_rsPCODE = mysql_fetch_assoc($rsPCODE);
if (isset($_GET['totalRows_rsPCODE'])) {
$totalRows_rsPCODE = $_GET['totalRows_rsPCODE'];
} else {
$all_rsPCODE = mysql_query($query_rsPCODE);
$totalRows_rsPCODE = mysql_num_rows($all_rsPCODE);
}
$totalPages_rsPCODE = ceil($totalRows_rsPCODE/$maxRows_rsPCODE)-1;
And I added this line on the page body to display the Sorry No Results Found message.
<?php if(isset($row_rsPCODE) && $row_rsPCODE == 0) {
echo "<h2>Sorry No Results Found</h2>";
}
?>
The problem here is that the Sorry No Results Found message displays on the page on page load even before the search is made instead of after the search is made because it is supposed to check the $row_rsPCODE
I have tried so hard to resolve it and kindly wish I could get a lead here.
Thank you in advance for the help
Mike
Have something to add?