Page 2 of 2

Posted: Wed Jan 25, 2006 8:19 pm
by Sculpture

Code: Select all

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());
$res = mysql_num_rows($qSearch);
$row_qSearch = mysql_fetch_assoc($qSearch);
and in the body where I want the message to be seen if there are no records.

Code: Select all

     <?php 
     if ( $res == 0) { 
            echo "No matching records." ;
            exit; 
            } 
     
     ?>
I have noticed that there is another "mysql_num_rows" elsewhere.

Code: Select all

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;
	}
}

Posted: Wed Jan 25, 2006 8:55 pm
by Bill H
I have noticed that there is another "mysql_num_rows" elsewhere.
Is this somebody else's code that you are trying to figure out?

If not, why are you executing the query a second time? Your question is becoming more and more difficult to understand with all of these little pieces of code that are not connected.

..and have no white space. Trying to read them is about to make my eyeballs explode.

Posted: Wed Jan 25, 2006 9:05 pm
by Sculpture
The main queries are delivered by the application that I am using. Sorry about the white space. I will endeavour to space it out a bit better.

Posted: Wed Jan 25, 2006 9:35 pm
by raghavan20
Bill H wrote:
I have noticed that there is another "mysql_num_rows" elsewhere.
Is this somebody else's code that you are trying to figure out?

If not, why are you executing the query a second time? Your question is becoming more and more difficult to understand with all of these little pieces of code that are not connected.

..and have no white space. Trying to read them is about to make my eyeballs explode.
What Bill told is true, I do not know what exactly the problem you have. You were earlier discussing about a query where you had problem with wrong syntax and suddenly you are jumping to mysql_num_rows().

Please do the following:
1. number and list each problem separately with their codes properly aligned.2
2. Tell in each problem, how do you expect the result to be.

Posted: Wed Jan 25, 2006 9:49 pm
by Sculpture
OK, thanks for your patience.

I only want to do one thing. I need to, "if there was no records found", say so in the <BODY> of the document. As you can see the functions and recordset that run the PHP are above the <HEAD> of the docuemt and can not be moved. I have tried assigning the entire top part of the HTML from the <HTML> tag down to where I want to have the message to a variable and echoing that but that doesn't work either. (I remembered to change all the " to ' as well. The syntax problem is probably my own.

Code: Select all

$res = mysql_num_rows($qSearch);
And in the body

Code: Select all

     if ( $res == 0) {  
            echo "No matching records." ; 
           exit;
}
      
Thanks again

Posted: Wed Jan 25, 2006 10:09 pm
by raghavan20
I do not really understand the whole of the earlier post you made but I assume this is what you wanted to do...

Code: Select all

<html>
<body>
<?php
	$query = "select * from `table_name` where `compare_string` like '%$target_string%'";
	$result = mysql_query($query);
	if (is_resource($result)){
		if (mysql_num_rows($result) == 0){
			echo "No matching records!!!";
		}
	}
?>
</body>
</html>
When you say, you have a problem, do not just post you have an error....post the errors output on the browser, if possible always provide a link to the working file. Do not just post one line of code, post more relevant code to it, if it is not a bigger file, post the entire file....

Posted: Wed Jan 25, 2006 10:34 pm
by Sculpture
Sorry,


This is the page with the search form. There is also another form with a dropdown menu that basicly does the same thing, so if I can fix on, I should be able to fix the other.

http://www.sportsmark.com.au


This is the results page


http://www.sportsmark.com.au/search_result.php


I have tried to move the recordset to the body before but it upsets the other functions.

Posted: Wed Jan 25, 2006 10:39 pm
by Sculpture
This is the entire page before I try to go in and put the "no records found then exit" function in, that I want to have after the "Home" button.

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"];

// 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);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<title>Sportsmark Super Store</title>

<link href="/sportsmark_thin.css" rel="stylesheet" type="text/css">

<script language="JavaScript" type="text/JavaScript">
<!--
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_nbGroup(event, grpName) { //v6.0
  var i,img,nbArr,args=MM_nbGroup.arguments;
  if (event == "init" && args.length > 2) {
    if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
      img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
      if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
      nbArr[nbArr.length] = img;
      for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
        if (!img.MM_up) img.MM_up = img.src;
        img.src = img.MM_dn = args[i+1];
        nbArr[nbArr.length] = img;
    } }
  } else if (event == "over") {
    document.MM_nbOver = nbArr = new Array();
    for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = (img.MM_dn && args[i+2]) ? args[i+2] : ((args[i+1])? args[i+1] : img.MM_up);
      nbArr[nbArr.length] = img;
    }
  } else if (event == "out" ) {
    for (i=0; i < document.MM_nbOver.length; i++) {
      img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
  } else if (event == "down") {
    nbArr = document[grpName];
    if (nbArr)
      for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
    document[grpName] = nbArr = new Array();
    for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = img.MM_dn = (args[i+1])? args[i+1] : img.MM_up;
      nbArr[nbArr.length] = img;
  } }
}
//-->
</script>
</head>

<body onLoad="MM_preloadImages('assets/link/home/locat_f3.gif','assets/link/home/locat_f2.gif')">
<div id="page" align="center">
  <div id="constraint">
  <div id="logo">
    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="760" height="130">
      <param name="movie" value="assets/masthead.swf">
      <param name="quality" value="high">
      <embed src="assets/masthead.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="760" height="130"></embed>
    </object>
  </div>
  
  <div id="contact"><span class="Red">Contact Sportsmark by Phone: 4124 3300 or eMail:</span> <a href="mailto:sales@sportsmark.com.au"><strong>sales@sportsmark.com.au</strong></a></div>
  <div id="home"> 
    <p> <a href="index.php" target="_top" onClick="MM_nbGroup('down','navbar1','locat','assets/link/home/locat_f3.gif',1);" onMouseOver="MM_nbGroup('over','locat','assets/link/home/locat_f2.gif','assets/link/home/locat_f3.gif',1);" onMouseOut="MM_nbGroup('out');"><img name="locat" src="assets/link/home/locat.gif" width="130" height="25" border="0" alt=""></a> <br>
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>
    <br>
    <strong>Click on a picture for details.</strong> 
</div>
  <div id="col1" align="left">

    <?php 
// Horizontal Looper start code for qSearch

do {
ob_start();
?>

    <table width="150" border="2" cellspacing="0" cellpadding="0">
  <tr>
    <td><?php echo $row_qSearch['name']; ?>	</td>
  </tr>
  <tr>
    <td><a href="detail.php?recordID=<?php echo $row_qSearch['entry_id']; ?>"><img src="images/<?php echo $row_qSearch['thumbnail']; ?>" width="150" height="160" border="0"></a></td>
  </tr>
</table>

    <?php
// HLooper manage the arrays for qSearch
$HLoop_qSearch_temp = ob_get_contents(); //dump buffer to variable
ob_end_clean(); //clear buffer
$HLoop_qSearch[$HLoop_qSearch_i][$HLoop_qSearch_ii] = $HLoop_qSearch_temp;
$HLoop_qSearch_ii++;
if($HLoop_qSearch_ii >= $HLoop_qSearch_loopTo){
	$HLoop_qSearch_i++;
	$HLoop_qSearch_ii = 0;
	$HLoop_qSearch_actualrows++;
};
} while ($row_qSearch = mysql_fetch_assoc($qSearch));
if($HLoop_qSearch_actualrows < $HLoop_qSearch_rows && $HLoop_qSearch_vertical == "false") $HLoop_qSearch_rows = $HLoop_qSearch_actualrows;
if($HLoop_qSearch_actualrows < $HLoop_qSearch_columns && $HLoop_qSearch_vertical == "true") $HLoop_qSearch_columns = $HLoop_qSearch_actualrows;

?>
<table>
<?php for($i = 0; $i < $HLoop_qSearch_rows; $i++) { ?>
<tr>
  <?php for($ii = 0; $ii < $HLoop_qSearch_columns; $ii++) { ?>
  <td><?php
            if($HLoop_qSearch_vertical == "true") {
              echo(isset($HLoop_qSearch[$ii][$i]) ? $HLoop_qSearch[$ii][$i] : "&nbsp;");
             }else{
              echo(isset($HLoop_qSearch[$i][$ii]) ? $HLoop_qSearch[$i][$ii] : "&nbsp;");
            } ?></td>
  <?php } ?>
</tr>
<?php } // End Horizontal/Vertical Looper code for qSearch ?>
</table>
  </div>
  </div>
</div>
</body>
</html>
<?php
mysql_free_result($qSearch);
?>

Posted: Wed Jan 25, 2006 11:24 pm
by Bill H
Sorry, there's just way more code there than I want to wade through
with no whitespace
poorly organized code
with no clear explanation of what the problem is
or where it is actually occurring
or what you actually want to accomplish.

Posted: Wed Jan 25, 2006 11:26 pm
by Sculpture
Thanks anyway