jj20051 Posted August 19, 2008 Share Posted August 19, 2008 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 More sharing options...
Mchl Posted August 19, 2008 Share Posted August 19, 2008 http://dev.mysql.com/doc/refman/5.0/en/select.html Search for "ORDER BY" Link to comment https://forums.phpfreaks.com/topic/120411-numerical-rank/#findComment-620427 Share on other sites More sharing options...
php_b34st Posted August 19, 2008 Share Posted August 19, 2008 why not order them as they come out of the database? SELECT * FROM websites WHERE `title` LIKE '%$keyword%' ORDER BY title; Link to comment https://forums.phpfreaks.com/topic/120411-numerical-rank/#findComment-620428 Share on other sites More sharing options...
jj20051 Posted August 19, 2008 Author Share Posted August 19, 2008 Well It Worked - Sort Of... Unfortunately it ranks the sites from lowest to highest ( a site with a rank of 4 is listed in the search results before one with a rank of 5 ) Link to comment https://forums.phpfreaks.com/topic/120411-numerical-rank/#findComment-620440 Share on other sites More sharing options...
akitchin Posted August 19, 2008 Share Posted August 19, 2008 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.