PDA

View Full Version : Number of links found


bloodjelly
01-08-2004, 06:58 PM
Hi -

I'd like to grab the total number of links found from the results array. It seems to be under "result_message", but I can't figure out how to get it yet. Any ideas? Thanks.

Just thought I'd mention the way I'm searching the array...I think it's faulty. Check it out: while ($results['results'][$i]['weight']){
// Add weight of results to total until loop finishes
$total += $results['results'][$i]['weight'];
$i++;
}
This adds the weights of the results but only the first 10. This is related to the first problem I think, because I can't figure out how to get all the results. Thanks again :)

Charter
01-09-2004, 05:13 AM
Hi. In search_function.php is the following:

$result_message = stripslashes(ucfirst(phpdigMsg('results'))." $n_start-$n_end, $num_tot ".phpdigMsg('total').", ".phpdigMsg('on')." \\"".htmlspecialchars($query_string)."\\" ($search_time ".phpdigMsg('seconds').")");

The $num_tot variable holds the number of results returned from a search. If you want to return $num_tot try the following.

In search_function.php replace:

if ($template == 'array' || is_file($template)) {
$phpdig_version = PHPDIG_VERSION;
$t_mstrings = compact('powered_by_link','title_message','phpdig_version','result_message' ,'nav_bar','ignore_message','ignore_commess','pages_bar','previous_link','n ext_link','templates_links');
$t_fstrings = phpdigMakeForm($query_string,$option,$limite,SEARCH_PAGE,$site,$path,'templ ate',$template);
if ($template == 'array') {
return array_merge($t_mstrings,$t_fstrings,array('results'=>$table_results));
}
else {
$t_strings = array_merge($t_mstrings,$t_fstrings);
phpdigParseTemplate($template,$t_strings,$table_results);
}
}

with the following:

$my_num_results = $num_tot;
if ($template == 'array' || is_file($template)) {
$phpdig_version = PHPDIG_VERSION;
$t_mstrings = compact('my_num_results','powered_by_link','title_message','phpdig_version' ,'result_message','nav_bar','ignore_message','ignore_commess','pages_bar',' previous_link','next_link','templates_links');
$t_fstrings = phpdigMakeForm($query_string,$option,$limite,SEARCH_PAGE,$site,$path,'templ ate',$template);
if ($template == 'array') {
return array_merge($t_mstrings,$t_fstrings,array('results'=>$table_results));
}
else {
$t_strings = array_merge($t_mstrings,$t_fstrings);
phpdigParseTemplate($template,$t_strings,$table_results);
}
}

Now <phpdig:my_num_results/> should be available for use in a template and hold the number of results returned from a search.

Remember to remove any "word" wrapping in the above code.

bloodjelly
01-09-2004, 10:50 AM
Perfect - works great. Thanks a lot for the quick reply. :D