简体   繁体   English

单击表格行以在新的php页面中显示该选定行的数据

[英]Click a table row to display the data of that chosen row in a new php page

At the moment, I can use a drop down list to retrieve data which is presented on a table. 目前,我可以使用一个下拉列表来检索表中显示的数据。 I want to make every row of a table clickable. 我想使表格的每一行都可单击。 Once I have clicked on that particular row, I want the data of that row (id, age, state, city, healthcare, team, cause, planned date, from and AAA_diam) to be displayed in a new php page. 单击特定行后,我希望该行的数据(id,年龄,州,城市,医疗保健,团队,原因,计划日期,来源和AAA_diam)显示在新的php页面中。 It should look like this and I hope that I'm being clear enough. 它看起来应该像这样,我希望我已经足够清楚了。

Display of information in a new PHP page once I've clicked on a row of a table. 单击表格的行后,将在新的PHP页面中显示信息。

Id: $id (from the table row)
age: $age
city: $city
healthcare: $healthcare
team: $team
cause: $cause
planned date: $planned date
from: $from
AAA_diam: $AAA_diam


<html>
    <head>
        <script type="text/javascript" src="script.js"></script>

    </head>
    <body>

        <form name="Select_filter3" method="POST" action="index.php">

    <select id="dropdown3" name="filter3">
        <option value=""></option>
        <option value="1">Amount of present</option>
        <option value="2">Amount of absent</option>
        <option value="3">Amount of present: destination</option>
        <option value="4">Antal of absent: destination</option>
        <option value="5">Amount A_diam > 3cm</option>
        <option value="6">Amount A_diam > 5cm</option>
</select>



    <input id="search_box2" type="text" name="search_box3" value="" />
    <input id="submit2" type ="submit" name ="search3" value ="Ok">

    </body>
</html>


<?php

include "connection1.php";

mysql_query ('SET NAMES UTF8;');
mysql_query ('SET COLLATION_CONNECTION=utf8_general_ci;');
mysql_client_encoding($connect);// where $conn is your connection





if (isset($_POST['search3'])) {

    switch($_POST['filter3']) {

        Default: 
            $sql = " ";
            break;

        case 1:
            $sql = "SELECT  * FROM mytable WHERE age = '35' AND city != 'Los Angeles'  ";


echo "<table border='1'>
<tr>
<th>ID</th>
<th>age</th>
<th>state</th>
<th>city</th>
<th>healthcare</th>
<th>Team</th>
<th>cause</th>
<th>Planned date</th>
<th>From</th>
<th>diameter</th>
</tr>";

$query = mysql_query($sql) or die(mysql_error());

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

  echo "<tr>";
  echo "<td>" . $row['id'] . "</td>";
  echo "<td>" . $row['age'] . "</td>";
  echo "<td>" . $row['state'] . "</td>";
  echo "<td>" . $row['city'] . "</td>";
  echo "<td>" . $row['healthcare'] . "</td>";
  echo "<td>" . $row['Team'] . "</td>";
  echo "<td>" . $row['cause'] . "</td>";
  echo "<td>" . $row[’planned date’] . "</td>";
  echo "<td>" . $row['from'] . "</td>";
  echo "<td>" . $row['AAA_diam'] . "</td>";
  echo "</tr>";
}

echo "</table>";
            break;   

mysql_close($connect);
?>
you can handle the click event of row using jQuery like

$(document).ready(function(){
    $("#your_table_id").delegate("tr.rows", "click", function(){

       /*find the clicked row id column and redirect to user for that record
         some thing like this http://www.yoursite.com/showrecord.php?id=5

         using location.href='http://www.yoursite.com/showrecord.php?id=5';
        */
    });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM