douxihui8270 2016-03-11 16:55
浏览 27
已采纳

如何在PHP中将搜索结果与HTML页面链接

Below is the code that i have written that would display data from phpmyadmin table and display the result. Now once the search result is displayed, let's say if i wish to click on one of the search result for e.g. i clicked on "Jon Doe" then upon click i should be redirected to the profile page (HTML page) of Jon Doe. May i know how do i do that ?

<?php
 echo "<body style='background-color:gray'>";
include ("account.php");
( $dbh = mysql_connect( $hostname, $username, $password ))
    or die ( "uable to connect to MYSQL database" );
mysql_select_db( $project );


if (isset($_POST['search'])) {
    $sql= "SELECT * FROM registration ";

    $search_term = mysql_real_escape_string($_POST['search_box']);

    $sql .= "WHERE first_name= '{$search_term}'";

    $sql .= " OR last_name= '{$search_term}'";
    $query=mysql_query($sql) or die(mysql_error());
}



?>



<html>  
<head>  
<title>jon</title>  
</head>  
<body>  
<form name="search_form" method="POST" action="retrieve.php">  
<table width="599" border="1">  
<tr>  
<th>Search

<input type ="text" name ="search_box" value=""/>
<input type="submit" name="search" value="Find Users">

</tr>  
</table>  
</form>  


<table width="600" border="1">  
<tr>  
<th width="91"> <div align="center">First Name </div></th>  
<th width="98"> <div align="center">Last Name </div></th>  
<th width="198"> <div align="center">Email </div></th>  
<th width="97"> <div align="center">City </div></th>  
<th width="59"> <div align="center">Country </div></th>     

<tr>


<?php  if (isset($_POST['search'])) {
while ($row=mysql_fetch_array($query)){ ?>


<tr>
    <td><?php echo $row['first_name'];?></td>
    <td><?php echo $row['last_name'];?></td>
    <td><?php echo $row['email'];?></td>
    <td><?php echo $row['address_city'];?></td>
    <td><?php echo $row['address_country'];?></td>



<tr>

<?php }} ?>

</table>

</div>
  • 写回答

2条回答 默认 最新

  • dongzhanbi0027 2016-03-11 17:12
    关注

    As Funk Doc already suggested you should make a "profile.php" for example which then queries all informations.

    First you need to link the profile page. You need a "id" from your database.

     <td><a href="profile.php?id=<?php echo $row['id'];?>"><?php echo $row['first_name'];?></a></td>
    

    Now you will redirect your user to profile.php with a special id.

    example: profile.php?id=87341

    In your profile.php you now need to get the id variable.

    profile.php

    <?php
    $userid = $_GET['id'];
    ?>
    

    The id is now saved in ´$userid´. Just search your database for that id and you get all your informations.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 从Freecad中宏下载的DesignSPHysics,出现如下问题是什么原因导致的(语言-python)
  • ¥30 notepad++ 自定义代码补全提示
  • ¥15 MATLAB有限差分法解一维边值问题
  • ¥200 内网渗透测试 横向渗透 Windows漏洞 Windows权限维持
  • ¥15 数据结构图的相关代码实现
  • ¥15 python中aiohttp.client_exceptions.ContentTypeError
  • ¥30 DeepLung肺结节检测生成最大froc值对应的epoch报错
  • ¥15 信号发生器如何将频率调大,步尽值改成10
  • ¥15 keil 5 编程智能家具,风扇台灯开关,人体感应等
  • ¥100 找一名渗透方面的专家