I want to say to the audience of the site that there are no records if that is the case and I want to do it down the body of the page.
Code: Select all
<?php
if (empty($colname)){
echo "No matching record found.";
exit;
}
?>Thanks
Moderator: General Moderators
Code: Select all
<?php
if (empty($colname)){
echo "No matching record found.";
exit;
}
?>Code: Select all
if (mysql_num_rows($row) < 1){
echo "No matching record found.";
exit;
}Code: Select all
if (mysql_num_rows($row) > 0){
// put code here for when rows are found
} else {
echo "No matching record found.";
}Code: Select all
<?php
if(!isset($tfm_rows) || intval($tfm_rows) == 0){$tfm_rows = 2;}
if(!isset($tfm_columns) || intval($tfm_columns) == 0){$tfm_columns = 4;}
if(!isset($tfm_vertical)){$tfm_vertical = "false";}
?>
<?php
//PHP version of DWTeam Dynamic Search SQL
//for qSearch
$tfmsqlstr = "";
if (isset($HTTP_POST_VARS["search"]) || isset($HTTP_GET_VARS["search"])){
$tfm_searchField = (isset($HTTP_POST_VARS["search"]))?$HTTP_POST_VARS["search"]:$HTTP_GET_VARS["search"];
if($tfm_searchField != "") {
$tfm_andor = "AND";
$tfm_exact = "false";
$bellChar = chr(7);
//if any words option
//not implemented
//if exact phrase option
//not implemented
$tfmsqlstr = " WHERE ((";
$tfm_databaseFields = explode(",","name,description");
if ((strstr($tfm_searchField,'"')) || ($tfm_exact == "true")){
$tfm_searchField = str_replace('"','',$tfm_searchField);
$tfm_andor = "OR";
}else
if (stristr($tfm_searchField," or ")){
$tfm_searchField = preg_replace('/\s+or\s+/i',$bellChar,$tfm_searchField);
$tfm_andor = "OR";
}else
if (strstr($tfm_searchField,',') || strstr($tfm_searchField,' ') || stristr(strtolower($tfm_searchField),' and ')) {
$tfm_searchField = preg_replace("/\s+and\s+/i",$bellChar,$tfm_searchField);
$tfm_searchField = str_replace(",",$bellChar,$tfm_searchField);
$tfm_searchField = str_replace(" ",$bellChar,$tfm_searchField);
}
$splitField = explode($bellChar,$tfm_searchField);
for ($i = 0; $i < sizeof($splitField) ;$i++){
for ($j = 0; $j < sizeof($tfm_databaseFields); $j++){
$tfmsqlstr = $tfmsqlstr."(".$tfm_databaseFields[$j]." LIKE '%".str_replace("'","''",$splitField[$i])."%')";
if ($j < sizeof($tfm_databaseFields)-1) $tfmsqlstr = $tfmsqlstr." OR ";
}
if ($i < sizeof($splitField) -1) $tfmsqlstr = $tfmsqlstr.") ".$tfm_andor." (";
}
$tfmsqlstr = $tfmsqlstr."))";
}else{
$tfmsqlstr = " WHERE 1=1 ";
}
}else{
$tfmsqlstr = " WHERE 1=1 ";
}
?>
<?php require_once('Connections/connect_front.php'); ?>
<?php
$currentPage = $_SERVER["PHP_SELF"];
if (!$tfm_search){
echo "No search term given.";
exit;
}
// Horizontal looper block 1 -- set up array, row and column values
$HLoop_qSearch = array();
$HLoop_qSearch_rows = $tfm_rows;
$HLoop_qSearch_columns = $tfm_columns;
$HLoop_qSearch_vertical = $tfm_vertical;
if($HLoop_qSearch_vertical == "true") {
$HLoop_qSearch_loopTo = $HLoop_qSearch_rows;
}else{
$HLoop_qSearch_loopTo = $HLoop_qSearch_columns;
}
$HLoop_qSearch_i = 0;
$HLoop_qSearch_ii = 0;
$HLoop_qSearch_actualrows = 1;
$maxRows_qSearch = $HLoop_qSearch_rows * $HLoop_qSearch_columns;
$pageNum_qSearch = 0;
if (isset($_GET['pageNum_qSearch'])) {
$pageNum_qSearch = $_GET['pageNum_qSearch'];
}
$startRow_qSearch = $pageNum_qSearch * $maxRows_qSearch;
$tfmsqlstr_qSearch = " WHERE 1=1 ";
if (isset($tfmsqlstr)) {
$tfmsqlstr_qSearch = (get_magic_quotes_gpc()) ? $tfmsqlstr : addslashes($tfmsqlstr);
}
mysql_select_db($database_connect_front, $connect_front);
$query_qSearch = sprintf("SELECT entry_id, name, thumbnail, description FROM entry %s ORDER BY name ASC", $tfmsqlstr_qSearch);
$query_limit_qSearch = sprintf("%s LIMIT %d, %d", $query_qSearch, $startRow_qSearch, $maxRows_qSearch);
$qSearch = mysql_query($query_limit_qSearch, $connect_front) or die(mysql_error());
$row_qSearch = mysql_fetch_assoc($qSearch);
if (isset($_GET['totalRows_qSearch'])) {
$totalRows_qSearch = $_GET['totalRows_qSearch'];
} else {
$all_qSearch = mysql_query($query_qSearch);
$totalRows_qSearch = mysql_num_rows($all_qSearch);
}
$totalPages_qSearch = ceil($totalRows_qSearch/$maxRows_qSearch)-1;
if ($HLoop_qSearch_rows < 1){
$HLoop_qSearch_rows = ceil($totalRows_qSearch / $HLoop_qSearch_columns);
if($HLoop_qSearch_loopTo < 1) {
$HLoop_qSearch_loopTo = $HLoop_qSearch_rows;
}
}
$queryString_qSearch = "";
if (!empty($_SERVER['QUERY_STRING'])) {
$params = explode("&", $_SERVER['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_qSearch") == false &&
stristr($param, "totalRows_qSearch") == false) {
array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString_qSearch = "&" . htmlentities(implode("&", $newParams));
}
}
$queryString_qSearch = sprintf("&totalRows_qSearch=%d%s", $totalRows_qSearch, $queryString_qSearch);
if (mysql_num_rows($qSearch) == 0) {
$result = TRUE;
}
?>Code: Select all
<?php
if ($qSearch = TRUE) {
echo "Sorry no results.";
exit;
}
?>Code: Select all
<?php
if ($qSearch = TRUE) {
echo "Sorry no results.";
exit;
}
?>Code: Select all
<?php
if ($qSearch == TRUE) {
?>Code: Select all
if ($qSearch) {Code: Select all
$qSearch = mysql_query($query_limit_qSearch, $connect_front) or die(mysql_error());
$qRes = mysql_num_rows($qSearch);
// a whole bunch of stuff can go here, including HTML
if ($qRes == 0)
{ echo "Sorry, no results";
}
else
{
// whatever, using $qSearch
}Code: Select all
$queryString_qSearch = "";
if (!empty($_SERVER['QUERY_STRING'])) {
$params = explode("&", $_SERVER['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_qSearch") == false &&
stristr($param, "totalRows_qSearch") == false) {
array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString_qSearch = "&" . htmlentities(implode("&", $newParams));
}
}
$queryString_qSearch = sprintf("&totalRows_qSearch=%d%s", $totalRows_qSearch, $queryString_qSearch);Code: Select all
Records <?php echo ($startRow_qSearch + 1) ?> to <?php echo min($startRow_qSearch + $maxRows_qSearch, $totalRows_qSearch) ?> of <?php echo $totalRows_qSearch ?>
<table border="0" width="50%" align="center">
<tr>
<td width="23%" align="center"><?php if ($pageNum_qSearch > 0) { // Show if not first page ?>
<a href="<?php printf("%s?pageNum_qSearch=%d%s", $currentPage, 0, $queryString_qSearch); ?>">First</a>
<?php } // Show if not first page ?>
</td>
<td width="31%" align="center"><?php if ($pageNum_qSearch > 0) { // Show if not first page ?>
<a href="<?php printf("%s?pageNum_qSearch=%d%s", $currentPage, max(0, $pageNum_qSearch - 1), $queryString_qSearch); ?>">Previous</a>
<?php } // Show if not first page ?>
</td>
<td width="23%" align="center"><?php if ($pageNum_qSearch < $totalPages_qSearch) { // Show if not last page ?>
<a href="<?php printf("%s?pageNum_qSearch=%d%s", $currentPage, min($totalPages_qSearch, $pageNum_qSearch + 1), $queryString_qSearch); ?>">Next</a>
<?php } // Show if not last page ?>
</td>
<td width="23%" align="center"><?php if ($pageNum_qSearch < $totalPages_qSearch) { // Show if not last page ?>
<a href="<?php printf("%s?pageNum_qSearch=%d%s", $currentPage, $totalPages_qSearch, $queryString_qSearch); ?>">Last</a>
<?php } // Show if not last page ?>
</td>
</tr>
</table>Code: Select all
<?php
if ($res == 0) {
echo "No matching records.";
exit;
}
?>And if there are no records the "No matching records" should be echo'd.You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '\'%t%\') OR (description LIKE \'%t%\'))) ORDER BY name ASC LIMIT
Where is the query? Echo the query to the browser and post it here....Sculpture wrote: To my mind if there are records returned the script should run as normal but I get.
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '\'%t%\') OR (description LIKE \'%t%\'))) ORDER BY name ASC LIMIT
Code: Select all
'\'%t%\'Code: Select all
'%\'t\'%'