PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
<?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 />';
}
}
?>
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
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.
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.
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.