gpt4 book ai didi

php MySQL 选择优先级

转载 作者:行者123 更新时间:2023-11-29 02:48:08 25 4
gpt4 key购买 nike

$query = "SELECT * FROM posts WHERE language='$lang' AND (title LIKE '%$search%' OR author LIKE '%$search%' OR year LIKE '%$search%')";  

这正是它应该做的。但我想做的是将“标题”作为优先事项。但是现在看起来(每个搜索都在 html 的下拉列表中)它简单地显示它没有优先级。所以标题可以在最底部,作者在顶部。错误的顺序。我想以某种方式始终将标题放在顶部。

如何?

$output = '';  
$lang = $_SESSION["lang"];
$search = $_POST["query"];
$query = "SELECT * FROM posts WHERE language='$lang' AND (title LIKE '%$search%' OR author LIKE '%$search%' OR year LIKE '%$search%')";
$result = mysqli_query($connect, $query);
$output = '<ul class="list-unstyled">';
if(mysqli_num_rows($result) > 0)
{
while($row = mysqli_fetch_array($result))
{

$output .= '<a href="'.$url.'/'.$lang.'/'.$row["url"].'/"><li>'.$row["book"].'</li></a>';
}
}
else
{
$output .= 'Not found.';
}
$output .= '</ul>';
echo $output;

最佳答案

您可以拆分查询。

  $output = '';  
$lang = $_SESSION["lang"];
$search = $_POST["query"];



$query2 = "SELECT * FROM posts WHERE language='$lang' AND title LIKE '%$search%'";
$result2 = mysqli_query($connect, $query2);
$output = '<ul class="list-unstyled">';
if(mysqli_num_rows($result2) > 0)
{
while($row = mysqli_fetch_array($result2))
{

$output .= '<a href="'.$url.'/'.$lang.'/'.$row["url"].'/"><li>'.$row["book"].'</li></a>';
}
}
else
{
$output .= 'Not found.';
}

$query = "SELECT * FROM posts WHERE language='$lang' AND (author LIKE '%$search%' OR year LIKE '%$search%')";
$result = mysqli_query($connect, $query);


if(mysqli_num_rows($result) > 0)
{
while($row = mysqli_fetch_array($result))
{

$output .= '<a href="'.$url.'/'.$lang.'/'.$row["url"].'/"><li>'.$row["book"].'</li></a>';
}
}
else
{
$output .= 'Not found.';
}


$output .= '</ul>';
echo $output;

关于php MySQL 选择优先级,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39387453/

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