gpt4 book ai didi

php - 如何重新排序搜索结果?

转载 作者:行者123 更新时间:2023-11-29 04:01:52 25 4
gpt4 key购买 nike

当我搜索单词“apple”时,脚本会按以下顺序显示结果:

(1) 苹果树(2) 果汁苹果(3) 苹果

但我想按以下顺序重新排列搜索结果:

(1) 苹果(2) 苹果树(3) 果汁苹果

如你所见,上面的顺序正是我想要的,结果是根据搜索词“apple”显示的

//get date
$button = $_GET['submit'];
$search = $_GET['search'];

if (!$button)
echo "Please fill out the form";
else
{
if (strlen($search)<=2)
echo "The item you searched for was to small";
else
{
echo "You searched for <b>$search</b> <hr size='1'>";

//connect to database

mysql_connect('localhost','wnumber','passowrd');
mysql_select_db('wnumber');


//explode search term
$search_exploded = explode(" ",$search);
foreach($search_exploded as $search_each)
{
$str = mysql_real_escape_string(substr($search_each, 0, 4));
//construct query
$x++;
if ($x==1) $construct .= "keywords LIKE '$str%'";
else $construct .= " OR keywords LIKE '$str%'";
}




//echo out construct
$construct = "SELECT * FROM word WHERE $construct";
$run = mysql_query($construct);
$foundnum = mysql_num_rows($run);

if ($foundnum==0)
echo "No results found.";
else
{

echo "$foundnum results found.<p><hr size='1'>";

while ($runrows = mysql_fetch_assoc($run))
{


//get data
$meaning = $runrows['meaning'];
$keywords = $runrows['keywords'];

echo "<b>$keywords</b><br>
<b>$meaning</b><br>

}

}



}
}

最佳答案

使用asc排序

$construct = "SELECT * FROM word WHERE $construct ORDER BY [Field Name from which you want ascend your search ] ASC";

关于php - 如何重新排序搜索结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13928248/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com