Jump to content

displaying number of results


cdoggg94

Recommended Posts

All i want to do is have a message for this search saying:

 

a) there are___ results found (if there is anything)

b) if there is no results..." there is no results for yours search

 

here is my search code

 

        <?php
//require_once("Connections/jodysConnect.php");
$mysearch = $_GET['findthis'];
//echo $mysearch;
mysql_select_db($database_TrendConnect);

$q = "SELECT * FROM Sheet1 WHERE pro_name LIKE '%" . mysql_real_escape_string($mysearch) . "%' OR lcbo_num LIKE '%" . mysql_real_escape_string($mysearch) . "%' ORDER BY pro_name ASC";

$mystuff = mysql_query($q);
//$num_rows = mysql_num_rows($result);

while($row = mysql_fetch_assoc($mystuff)) {
echo "<table border='0'><tr><td>";?><a href="#" onClick="MyWindow=window.open('<?php echo "http://www.THISWEBSITE.com/Agency/product3.php?Product=".$row['pro_id']; ?>','MyWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=800,height=886'); return false;"><?php echo $row['pro_name']."</a><br /></td></tr></table>";
}
?>

Link to comment
https://forums.phpfreaks.com/topic/264711-displaying-number-of-results/
Share on other sites

yea sorry that's kind of what it seemed like...

 

I was thinking that

$num_rows = mysql_num_rows($mystuff) ;

 

then..

 

if($num_rows >= 1){

  echo "you have".$num_rows."results";

}

 

if($num_rows ==0){

echo "there were no results found";

}

 

im just not sure if the $num_rows thing is what im looking for.

If you need to use actual data returned from a query (and it seems you do) then mysql_num_rows() is the right choice. If all you need is to find the number of records that a particular query returns, then you'd just use a SELECT COUNT() query.

Well I have this:

 

        <?php
//require_once("Connections/jodysConnect.php");
$mysearch = $_GET['findthis'];
//echo $mysearch;
mysql_select_db($database_TrendConnect);

$q = "SELECT * FROM Sheet1 WHERE pro_name LIKE '%" . mysql_real_escape_string($mysearch) . "%' OR lcbo_num LIKE '%" . mysql_real_escape_string($mysearch) . "%' ORDER BY pro_name ASC";

$mystuff = mysql_query($q);
$num_rows = mysql_num_rows($mystuff);

if($num_rows >= 1){
echo "<span class='Graphtitle'>There were ".$num_rows." results for your search!</span><br /><br />";

while($row = mysql_fetch_assoc($mystuff)) {
echo "<table border='0'><tr><td>";?><a href="#" onClick="MyWindow=window.open('<?php echo  "http://www.THISWEBSITE.com/Agency/product3.php?Product=".$row['pro_id']; ?   >','MyWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width= 800,height=886'); return false;"><?php echo $row['pro_name']."</a><br /></td></tr></table>";
}
}

if($num_rows == 0){
echo "<span class='Graphtitle'>There were no results for your search</span>";
}

?>

 

It seems to be working.  I don't know if its done in the best way possible, but it does seem to be doing what I want it to do.

 

Thanks anyways for the help

 

Cheers

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.