从搜索结果中搜索范围较窄

时间:2013-03-19 08:23:11

标签: php database search username

我正在尝试缩小我正在玩的游戏的搜索结果。

我正在尝试通过单击显示的特定用户来缩小搜索结果范围。单击用户后,需要显示该用户的所有数据库条目。

例如。

我的dbase字段为: - Alliance, User, Might

当我搜索“联盟”时,我目前获得该联盟中所有用户的列表

我想点击特定的“用户”,只显示该用户的结果

这是我到目前为止所拥有的

    <?php
     mysql_connect ("localhost","my username","password")  or die (mysql_error());
        mysql_select_db ("my_dbase");

  $term = $_POST['term'];


  $data = mysql_query("select * FROM my_table WHERE alliance like '%$term%' ORDER BY type, alliance, might DESC");

        echo "<table border='1' cellpadding='5'>";
        echo "<tr> <th>Alliance</th> <th>User</th> <th>Might</th> </tr>";

        // loop through results of database query, displaying them in the table

        while($row = mysql_fetch_array( $data )) {

        // echo out the contents of each row into a table

                echo "<tr>";
                echo '<td>' . $row['alliance'] . '</td>';
                echo '<td>' . $row['user'] . '</td>';
            echo '<td>' . $row['might'] . '</td>';
                echo "</tr>";
        } 

        // close table>
        echo "</table>";
  ?>

任何帮助都会很棒。

1 个答案:

答案 0 :(得分:0)

您需要为用户详细信息页面设置链接,如下所示

echo '<td><a href="userDetail.php?userID='.$row['id'].'">' . $row['user'] . '</a></td>';

创建一个名为userDetail.php的新页面,然后根据传递的userID激活SELECT查询,并在那里拥有它。