Page 1 of 1

pagnation

Posted: Sat Feb 23, 2008 2:21 am
by patty07
I want to add pagnation to this but have no clue on how to do it
Please help me if you can..

Code: Select all

 
 
<?php
//I want to add pagnation to this but have no clue
//Please help if you can
 
//Not sure about this function on what needs to be edited as far as results per page
//I am sure that in the $ret line that the page variable needs to be a varible as to what page is what were on
$q = htmlentities($_GET['q']);
 
function searchFeedResults($q, $results,  $tID, $pID)
{
  $res = array();
  $ret=file("http://www.searchfeed.com/rd/feed/TextFeed.jsp?trackID=".$tID."&excID=&pID=".$pID."&cat=".urlencode($_GET['q'])."&nl=".$results."&page=1&ip=".$_SERVER["REMOTE_ADDR"]);
  if ( count($ret) == 0 ) return $res;
  for ( $i=0;$i<count($ret);$i=$i+5 )
  {
   $j = $i;
   for ( $j=$i;$j<($i+4);$j++)
   {
     $a = explode('|',$ret[$j]);
     $tmp[] = $a[2];
   }
   $res [] = $tmp;
   unset($tmp);
  }
  return $res;
}
 
 
$myTid = 'changeme';
$myPid = 'changeme';
 
echo '
<p>
    Search :
    <form method="get" action="'.$_SERVER['PHP_SELF'].'" />
     <input type="text" name="q" value="'.$_GET['q'].'" /> 
     <input type="submit" value="Go" />
    </form>
</p>';
if ( !empty($_GET['q'])){
    $results = searchFeedResults($_GET['q'], 5, $myTid, $myPid );//5 is how many results per page
    if ( $results ){
         foreach ( $results as $rec ){
            echo '
            <p>
              <a href="'.$rec[2].'" onmouseover="window.status=\'http://'.$rec[1].'\'; return true"
    onmouseout="window.status=\' \'; return true">'.$rec[0].'</a><br />
              '.$rec[3].'<br />
              <small>'.$rec[1].'</small>
            </p>';
         }
//need to add pagnation here
    }else{
         echo 'No results for '.$_GET['q'].'<br /><br />';
    }
}
?>
 

Re: pagnation

Posted: Sat Feb 23, 2008 2:41 am
by staar2
easiest pagination is something like this [1-10] [10-20]
1.So you need know how many rows are in table
2.Divide the total rows by rows per page, now you know how many pages you get
3. Display the links [1-10]
4. Make some page id so you can make query to mysql with LIMIT 1, 10

Re: pagnation

Posted: Sat Feb 23, 2008 5:06 am
by patty07
If you look at code, I do not get to run a query, I have what I have above to work with.
Which is why I need help in making the pagnation.

Re: pagnation

Posted: Sat Feb 23, 2008 11:58 am
by Christopher
Have you tried changing "&page=1" to "&page=2" and see what you get? If that works then you could pass in $page and change that to "&page=$page" .

Otherwise, you will probably need to get all the results and only show a fixed number. To reduce calls to your feed, perhaps you could generate a Javacript array of all your feed data and use Javascript to do the paging.

Re: pagnation

Posted: Sat Feb 23, 2008 12:23 pm
by patty07
Well I have tried everything and even went to searchfeed.com and tested theirs and most results I was getting was 20..

So if anyone knows of another reliable search that I can alot more results and use pagnation and one that allows me to edit looks of results, that would be great.

Re: pagnation

Posted: Sat Feb 23, 2008 12:46 pm
by Christopher
patty07 wrote:Well I have tried everything
:)

Can you tell us things that you tried?

Re: pagnation

Posted: Sat Feb 23, 2008 1:03 pm
by patty07
Well I tired something like this to get total results, but it always showed 100 when there really was just 20 results when I went to searchfeed.com
Starting to think maybe I should look for another engine that allows more results and something to configure easy.

Code: Select all

 
 
  $res = array();
  $ret=file("http://www.searchfeed.com/rd/feed/TextFeed.jsp?trackID=".$tID."&excID=&pID=".$pID."&cat=".urlencode($_GET['q'])."&nl=".$results."&page=1&ip=".$_SERVER["REMOTE_ADDR"]);
 
   if ( count($ret) == 0 ) return $res;
   $numResults = count($ret);//Always no matter what searchword, shows 100
 
 
 
Also if you go to searchfeed.com and do any kind of a search, I couldnt even get past 20 results found.
I think that tells me alot.