I think there is something wrong with my uasort..
What I do is count the word matches and add them up, then stow them in the row as 'score'..
Then I do a uasort on the rows with the sort function looking at the 'score' of each row.
However, when I print out my results, the order is never right. It seems almost random on the first page, then least to most result matches on the 2nd page.. Obviously I'm looking to list most to least over multiple pages..
here is the specific code in question:
while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$row[score] = count_words($row[video_desc]);
$rows[] = $row;
}
uasort($rows, "search_rank");
function search_rank($a, $b) {
$ax = $a[score];
$bx = $b[score];
if($ax == $bx) {
return 0;
}
return ($ax > $bx) ? -1 : 1;
}
There is the scoring process and sorting.. below is how it is all printed out:
for($rowtoprint = $rowtoprintstart; $rowtoprint <= $rowtoprintend; $rowtoprint++) {
$rowarray = $rows[$rowtoprint];
$title = $rowarray["video_name"];
$desc = $rowarray["video_desc"];
$path = "/h1/adamspro/".$rowarray["video_path"];
$category = $rowarray["video_cat"];
$id = $rowarray["id"];
if($rowarray["score"] == 1) {
$score = "<font face=\"Arial, Verdana\" size=\"1\">".$rowarray["score"]." WORD MATCH</font>";
}
else {
$score = "<font face=\"Arial, Verdana\" size=\"1\">".$rowarray["score"]." WORD MATCHES</font>";
}
$fsize = filesize_short($path);
$prettydesc = highlight_words($desc);
echo("<br><br><b>$count. <a href=\"http://www.XXXXXXXXX.com/videodat/video.php?id=$id\" target=\"_blank\">$title</a></b> ($fsize) ($score) <br>$prettydesc ");
$count++;
}
I don't think the display code has anything to do with the problem, but if I knew what the problem was I wouldn't be asking this question on the forums 🙂.
Thanks for any help anyone can provide.. This is the first real wall I've run into so far with PHP!
--tgmsocal