如何使搜索栏中的链接转到其他页面?

莎拉

我目前有一个工作正常的搜索栏,并且按我想要的方式工作,我只是想知道是否可以将链接添加到不同的项目中?现在,所有搜索到的重定向到'Session.php'的内容是否都可以显示?如果有人搜索“ Home”,我可以显示结果,然后用户可以单击“ Home.php”吗?谢谢!

Search.php代码:

<?php 
//--- Authenticate code begins here ---
session_start();
//checks if the login session is true
if(!isset($_SESSION['sess_user'])){
header("location:index.php");
}
$username = $_SESSION['sess_user'];

// --- Authenticate code ends here ---
 ?> 

 <link rel="stylesheet" type="text/css" href="../css/style1.css">
 <?php
    mysql_connect("localhost", "root", "") or die("Error connecting to database: ".mysql_error());
    mysql_select_db("aha") or die(mysql_error());
?>
<html>
</html>

登出

    <head>
    <title>Search results</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link rel="stylesheet" type="text/css" href="style.css"/>
</head>
<body>
<?php
    $query = $_GET['query']; 


    $min_length = 3;


    if(strlen($query) >= $min_length){ // if query length is more or equal minimum length then

        $query = htmlspecialchars($query); 
        // changes characters used in html to their equivalents, for example: < to &gt;

        $query = mysql_real_escape_string($query);
        // makes sure nobody uses SQL injection

        $raw_results = mysql_query("SELECT * FROM articles
            WHERE (`title` LIKE '%".$query."%') OR (`text` LIKE '%".$query."%')") or die(mysql_error());

        // * means that it selects all fields, you can also write: `id`, `title`, `text`
        // articles is the name of our table

        // '%$query%' is what I'm looking for, % means anything, for example if $query is Hello
        // it will match "hello", "Hello man", "gogohello", if you want exact match use `title`='$query'
        // or if you want to match just full word so "gogohello" is out use '% $query %' ...OR ... '$query %' ... OR ... '% $query'

       if(mysql_num_rows($raw_results) > 0){ // if one or more rows are returned do following

    while($results = mysql_fetch_array($raw_results)){
    // $results = mysql_fetch_array($raw_results) puts data from database into array, while it's valid it does the loop



echo "<a href='../pages/session.php'><h3>{$results['title']}</h3></a><p>{$results['text']}</‌​p>";



    }


}
    else{ // if there is no matching rows do following
    echo ("<br><br>No results</br></br>");
}

}

else{ // if query length is less than minimum
echo ("</br></br>Minimum length  is</br></br> ".$min_length);
}

?>


</body>

<br>
<br>
<a class="btn btn-search" type="button" href="index.php" >Search Again</a>
</br>
</br>




 DB FOR ARTICLE:

http://puu.sh/ctUUq/2f73509cf2.png

谢谢!

比古德

您必须将每个记录的页面名称存储在数据库中,然后通过查询对其进行检索。

考虑到您要将其存储在SQL表上名为“ page_name”的列中,请根据用户的查询将这一行更改为指向正确的页面:

echo "<a href='../pages/{$results['page_name']}'><h3>{$results['title']}</h3></a><p>{$results['text']}</‌​p>";

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

保存链接分配值以及转到其他页面

搜索其他查询时如何获取搜索中的其他链接

PHP-如何在CI中链接其他页面

当用户单击链接时,如何在转到其他页面之前滚动到顶部?

支付成功如何跳转到其他页面

在离子搜索栏中搜索其他项目时,如何保持选中的项目?

完成html中的视频后,转到其他页面

如何将标签栏添加到其他页面,而不是在标签栏菜单中

如何将我的帖子创建者页面链接到Python中的其他页面?

在进度栏运行时如何禁用WPF中页面的其他控件

单击ReactJs中表行中的链接时如何在其他页面中呈现组件

如何制作覆盖其他HTML元素的搜索栏表单?

如何显示搜索栏与其他元素的“内联”

引导导航栏在其他玉文件中搜索

如何在Google搜索中显示您网站上的其他链接

如何在reStructuredText中添加到其他页面的链接?

React:如何链接到其他组件(在同一页面中打开)

如何使用“ MDL选项卡”链接到页面中的位置而不隐藏其他内容

如何使可点击的行链接到其他页面

仅从特定链接执行其他页面中的jQuery函数

链接到 Drupal 8 中的其他页面

如何使用导航栏项转到其他视图控制器?

不要在首页上显示搜索栏,而是在所有其他页面上显示

导航栏链接在其他页面上打开选项卡吗?

如何不链接a href转到“关于页面”?

如果网页在HTML / JavaScript中不可用,请转到其他链接

转到其他页面后如何在文本框中保留值?

ionic2 如何只设置点击图标并转到其他页面

如何使用jsp变量传输onclick并直接转到其他页面