如何在搜索查询中使用链接的值

时间:2018-02-24 15:52:27

标签: php url search hyperlink

有人可以帮我解决这个问题吗? 单击链接时,它将定向到包含与链接值相关的内容的新页面。例如,在单击文章标题后,它将被定向到包含其内容的新页面。因此链接的值将用于搜索。

2 个答案:

答案 0 :(得分:0)

index.php

   <?php

   $host = "localhost";
   $username="root";
   $password="";
   $database="silangagri";

   $connect = new 
   PDO("mysql:host=$host;dbname=$database",$username,$password);
   $connect->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

   $query = "SELECT * FROM news ORDER BY date DESC";
   $data = $connect->query($query);
            ?>

   <!DOCTYPE html>

   <html>
   <body>
    <form action = "search.php" method="post">
    <?php foreach($data as $row) { 
    echo '<a name="valueTosearch" href="search.php">
    <h5>'.$row["title"].'</h5></a>'; 
    echo '<br><br>';?>
    <?php 
    }
    ?>
    </form>

    </body>
    </html>

答案 1 :(得分:0)

的search.php

<?php 

if(isset ($_POST['valueTosearch']))
{
$valueToSearch = $_POST['valueToSearch'];
$query = "SELECT * FROM `events` WHERE CONCAT(`title`) LIKE 
'%".$valueToSearch ."%'";
$search_result = filterTable($query); 


 }
 else {
 $query="SELECT * FROM `events`";
 $search_result = filterTable($query);
 }




 function filterTable($query)
 {
 $connect = mysqli_connect("localhost", "root", "", "silangagri");
 $filter_Result = mysqli_query($connect, $query);
 return $filter_Result;  
 }

 ?>



 <!DOCTYPE html>

<html>
<head>
<title>PHP HTML TABLE DATA SEARCH</title>
<style>
    table,tr,th,td
    {
        border: 1px solid black ;
    }
</style>

</head>
<body>

<table style="padding-right:  2; padding-left: 2; padding-top: 4; padding-
bottom: :4">
<tr>
    <th>title</th>
    <th>location</th>



</tr>
<?php while($row = mysqli_fetch_array($search_result)): ?>
    <tr>

    <td><?php echo $row['title']; ?></td>
    <td><?php echo $row['location']; ?></td>


    </tr>

<?php endwhile;?>


</table>

</body>

</html>