我已经在我的网站中进行搜索,我希望输入查询后
链接将为$results['title']
,但它将用-
行:
web = str_replace(' ','-',$results['title']);
我想要这个:
this-is-a-example.php
此处是完整代码:
$query = $_GET['query'];
$title = $raw_results['title'];
$web = str_replace(' ','-',$results['title']);
$min_length = 1;
if(strlen($query) >= $min_length){
$query = htmlspecialchars($query);
$query = mysql_real_escape_string($query);
$raw_results = mysql_query("SELECT * FROM content WHERE (`title` LIKE '%".$query."%') OR (`text` LIKE '%".$query."%') OR (`link` LIKE '%".$query."%') ") or die(mysql_error());
if(mysql_num_rows($raw_results) > 0){
while($results = mysql_fetch_array($raw_results)){
echo "<a href='https://example.com/".$web.".php'><h3>".$results['title']."</h3></a><br>";
echo "<p>".$results['title']."</p>";
}
}
else{
echo "No results";
}
}
else{
echo "Minimum length is ".$min_length;
}
当我尝试打开链接时,它只运行/.php。
谢谢您的答复
答案 0 :(得分:-1)
由于查询结果返回多行,因此需要将$web
置于while
循环下。
每个文件名也应小写,我用strtolower
将其转换为小写。
尝试以下代码:
$query = $_GET['query'];
$title = $raw_results['title'];
$min_length = 1;
if(strlen($query) >= $min_length){
$query = htmlspecialchars($query);
$query = mysql_real_escape_string($query);
$raw_results = mysql_query("SELECT * FROM content WHERE (`title` LIKE '%".$query."%') OR (`text` LIKE '%".$query."%') OR (`link` LIKE '%".$query."%') ") or die(mysql_error());
if(mysql_num_rows($raw_results) > 0){
while($results = mysql_fetch_array($raw_results)){
$web = strtolower(str_replace(' ','-',$results['title']));
echo "<a href='https://example.com/".$web.".php'><h3>".$results['title']."</h3></a><br>";
echo "<p>".$results['title']."</p>";
}
} else {
echo "No results";
}
} else {
echo "Minimum length is ".$min_length;
}