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
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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.