For instance if I have 3 fields:
title, filename, and html
I want terms with the query in the title and filename and html to ouput first, then the terms with title and filename, then filename and html, then filename, then html.. but I dont want the same record outputted twice.
Also I am searching multiple tables useing a union.. I dont think this will matter but the results will also be page-inated
here is my current code (tested, and is currently in use on the website)
right now it only searches the titles... where the title includes all the terms entered, how can I also make it so it will search where like '%termone%' and like '%termtwo%' and then do it with or's that way a field containing all terms will be outputted first then a field with only some of the terms.
Is this even possible with mysql?
Code: Select all
<?php
function makelike() {
$q=secure(urldecode($_REQUEST['query']));
$q=explode(" ", $q);
$like=NULL;
$count=0;
foreach($q as $term) {
$count++;
$like .="LIKE '%" . secure($term) . "%'";
if ($count!=count($q)) {
$like .= " and `title` ";
}
}
return($like);
}
function make ($action, $system) {
if ($action=='count') {
$query="SELECT count(*) FROM $system WHERE `title` " . makelike() . " ; ";
} else {
$query="($action `title`, `filename`, `sys` FROM `" . $system . "` WHERE `title` " . makelike() . " ORDER BY `title`)";
}
return ($query);
}
function build($action) {
$query=(make($action, 'ps2') . " UNION " . make($action, 'xbox') . " UNION " . make($action, 'pc'));
return($query);
}
$query=make('count', 'ps2');
$result = dbq($query);
$found = $result[0];
$query=make('count', 'xbox');
$result = dbq($query);
$found = $found + $result[0];
$query=make('count', 'pc');
$result = dbq($query);
$found = $found + $result[0];
$start = secure((int)$_REQUEST['start']);
$perpage = 20;//change this to whatever number you like.
$query=build('select') . "LIMIT $start, " . secure($perpage) . " ; ";
$result=mysql_query($query) or die(mysql_error());
echo '<table width=100% border=1 bordercolor=black>';
$query='''' . htmlentities($_REQUEST['query']) . '''';
echo '<tr><td colspan=2 align=center><b>Onlycheaters search results for ' . $query . '</b><BR>(Found <i>' . $found . '</i> results)</td></tr>';
while (list($title, $filename, $sys) = mysql_fetch_array($result)) {
echo ("<tr><td><a href='/$sys/$filename'>$title</a></td><td>$sys</td>");
}
echo '</table>';
echo nextpage($perpage,$start,$_SERVER['PHP_SELF'], "", $found) . "</center>";
?>I don't know even how to go about this... If I can get mysql to never return an item it has already returned by like putting distinct() around the while thing that would be a start, but I would have to get it to order the results in the correct way, giveing certaint fields more priority over others and also the issue with like '' OR like '' as to like '' AND like '' (give items with both terms a higher priority)