Jump to content

Recommended Posts

Hi All,

 

I have a pagination script that works correctly when a user clicks on a category heading, however when I am using it to try an display search results it does not take into account the set of records to display per page, it just shows all results.

 

<?php


echo '<h3>Search Results</h3><br />';



$query = "SELECT count(*) from merchants WHERE name LIKE '%$_GET[q]%' OR short like '%$_GET[q]%' OR full like '%$_GET[q]%' OR keywords like '%$_GET[q]%'"; 
$row=mysql_fetch_assoc(mysql_query($query));
$total_records = $row['count(*)'];
$records_per_page = 5;
$total_pages = ceil($total_records / $records_per_page);
$page = intval($p);
if ($page < 1 || $page > $total_pages) $page = 1;
$offset = ($page - 1) * $records_per_page; 

$limit = " LIMIT $offset, $records_per_page";



$query = mysql_query("SELECT * FROM merchants WHERE name LIKE '%$_GET[q]%' OR short like '%$_GET[q]%' OR full like '%$_GET[q]%' OR keywords like '%$_GET[q]%' ORDER BY m_id  DESC") ; 
echo mysql_error() ;



while($row = mysql_fetch_assoc($query)){

$name = $row['name'];
$short = $row['short'];
$per = $row['percent'];
$m_id = $row['m_id'];

?>
    
    <div id="cbbox">
    <a href="viewm.php?m_id=<?php echo $m_id;?>">
    	<div class="cbname">
        	<?php echo $name;?>   - Up to <?php echo $per ;?>% Cashback Available
        </div>
        <div class="cbimage">
        	<img src="pimage/<?php echo $name;?>.gif" height="50px" width="100px" />
        </div>
      <div class="cbshort">
        	<?php echo $short;?>
        </div>
        </a>
        <div class="cbtweet">
       	<a href="http://twitter.com/home/?status=Get up to <?php echo $per;?> percent Cashback on purchase from <?php echo $name;?> http://goo.gl/PLkp"><img src="images/cbtweet.png" width="90" height="50" alt="Tweet This" /></a>

        </div></div>
	<br /><br />
<?php
}
if($total_records > 5)
{
for ($i = 1; $i <= $total_pages; $i++) {
echo "<a title='page $i p=$i'>Page $i -  </a>";
}
}

?>
</div>

 

if I echo out $total_records it displays the correct amount (7 in the case I am looking at)

 

Any ideas?

Link to comment
https://forums.phpfreaks.com/topic/218443-search-engine-results-pagination-help/
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.