I have an array $r generated from the following code:
Code: Select all
function return_relevancy($result,$q_num, $q_array, $keyword_set)
{
$num_results = mysql_num_rows($result);
//for each result get variables
for ($c=0;$c<$num_results;$c++)
{
$relevancy = 0;
$row = mysql_fetch_object($result);
$mypage=$row->product_id;
$mycontent=strtolower(strip_tags($row->long_desc));
$mytitle = strtolower(strip_tags($row->title));
$strap_line = strtolower(strip_tags($row->strap_line));
$intro = strtolower(strip_tags($row->intro));
$keywords = strtolower(strip_tags($row->keywords));
$ed_desc = strtolower(strip_tags($row->ed_desc));
$theme = strtolower(strip_tags($row->theme));
$who = strtolower(strip_tags($row->who));
//if there were no keywords searched for to not perform rankings
if ($keyword_set == "no")
{
$res["$mypage"] = $relevancy;
}
else {
//perform relevancy test
for ($d=0; $d<$q_num; $d++)
{
$relevancy+=substr_count($mycontent, strtolower(strip_tags($q_array[$d])));
//if keyword is in title
if(substr_count($mytitle, strtolower(strip_tags($q_array[$d]))))
{
$relevancy=$relevancy + 10;
}
//if keyword is in strap line
if(substr_count($strap_line, strtolower(strip_tags($q_array[$d]))))
{
$relevancy=$relevancy + 10;
}
//if keyword is in intro
if(substr_count($intro, strtolower(strip_tags($q_array[$d]))))
{
$relevancy=$relevancy + 1;
}
//if keyword is in keywords
if(substr_count($keywords, strtolower(strip_tags($q_array[$d]))))
{
$relevancy=$relevancy + 5;
}
//if keyword is in ed_desc
if(substr_count($keywords, strtolower(strip_tags($q_array[$d]))))
{
$relevancy=$relevancy + 5;
}
//if keyword is in theme
if(substr_count($theme, strtolower(strip_tags($q_array[$d]))))
{
$relevancy=$relevancy + 3;
}
//if keyword is in who
if(substr_count($who, strtolower(strip_tags($q_array[$d]))))
{
$relevancy=$relevancy + 2;
}
} //end of for
//if an activity has a relevancy of at least 1 display it in search results
if ($relevancy>0)
$res["$mypage"] = $relevancy;
}
}
//sort results
if(count($res)>0)
arsort ($res);
return $res;
}And I display it throught the following function:
Code: Select all
function print_answers($r)
{
$no_results = (count($r));
//display results header
print '<table width="100%" cellspacing="0" cellpadding="0" ><tr><td class="resultsline">'.$no_results.' training activities returned</td></tr>
<tr>'; pagernumber($page, $i, $pager); print'</tr></table><br>';
//if there were no results display error
if (count ($r) <1)
{
print 'nothing found';
}
else
{
while($element=each($r))
{
$act_id = $element["key"];
$row = activity_query($act_id);
$title = $row['title'];
$short_desc = $row['short_desc'];
$man_id = $row['relation'];
$row = manual_query($man_id);
$man_title = $row['man_title'];
//display
Print '<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td><p><strong><a href="activity.php?act_id='.$act_id.'" class="resulttitle">'.$title.'</a></strong></td><td align="right"> <span align ="right" class="italicmanual">featured in: '.$man_title.'</span><td><tr><table>
<div class="shortdesc">'.$short_desc.'</div></p>';
print ' activity '.$element["key"].'&'.$element[1].'</br>';
}
}
}what I want to do is split the results into pages of 10 results per page, i.e. i want to use paging.
However the method I have used in the past has involved limiting the mysql queries, while the relevany function reduces these queries into smaller numbers of results (if u see what i mean!)
I was wondering if there was anything that I could perform on $r in the print_answers() function to achieve this??
i hope this makes sense, thanks in advance
alex