Jump to content

Numerical Rank


jj20051

Recommended Posts

I Have Created A "search script" that searches thru the database and displays the results. Now i want to rank those results based on a number stored in the database. Each result has it's own number. The site with the highest number is displayed first - the site with the lowest number is last. Here is the portion of the script that does the searching.

 

 

{
$keyword = limpiar($_POST['keyword']);
if ($keyword == NULL) {
echo "<center><strong>You did not enter any keywords into the search box!</center></strong>";
}else{
	$result=mysql_query("SELECT * FROM websites WHERE `title` LIKE '%$keyword%' OR `url` LIKE '%$keyword%' OR `description` LIKE '%$keyword%' OR `keywords` LIKE '%$keyword%' ");
	while ($results = mysql_fetch_array($result))
	{
		$title=$results['title'];
		$url=$results['url'];
		$description=$results['description'];
		echo "<a href='$url'>$title</a><br><i>$description</i><br><font color=\"#339900\">$url</font><br><br>";
	}
}
}

Link to comment
https://forums.phpfreaks.com/topic/120411-numerical-rank/
Share on other sites

check the field type that the rank has in the database. if it's varchar(), it won't order numerically. also, switching the order is simply a matter of assigning:

 

ORDER BY field DESC

 

over

 

ORDER BY field

 

(which is the same as:)

 

ORDER BY field ASC

Link to comment
https://forums.phpfreaks.com/topic/120411-numerical-rank/#findComment-620445
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.