如何在动态表中的每一行中添加超链接?

时间:2013-01-16 12:22:50

标签: php sql mysqli html-table

serialID(AI)|locations | telephone | address
---------------------------------------------
1           | A       
2           | B
3           | C
4           | D

users table
userID | location choosen
-------------------------
1      | A
2      | B
3      | B

如何在动态表格的每一行中添加超链接?

例如(这是一个动态表),它会改变..取决于用户的利益。

location | address | telephone | user's favourable
B        |  -      | -         |  2
A        |  -      | -         |  1
C        |  -      | -         |  0
D        |   -     | -         |  0

因此,如果我将鼠标悬停在A行,我可以转到另一个php页面并显示必要的详细信息示例,例如用户选择位置A.有没有办法做到这一点?请帮忙。

这是创建表格代码 - >

<?php
include mysqli.connect.php";

   $retrieveLocation = SELECT l.locations, l.telephone, l.address, COUNT (u.userID) as userID
    FROM location AS l
    LEFT OUTER JOIN users AS u on l.locations = u.location_chosen
    GROUP BY l.locations
    ORDER BY userID DESC;

   $result = $mysqli->query($retrieveLocation);

      while ($row = $result->fetch_array(MYSQLI_ASSOC))
      { 
        echo "<tr><td>{$row['locations']}</td><td>{$row['telephone']}</td><td>{$row['addression']}</td><td>{$row['userID']}</td></tr>";
      }
?>

1 个答案:

答案 0 :(得分:0)

尝试使用此代码在html + php中生成表格:

<table>
<thead>
<tr>
<th>Location</th>
<th>Address</th>
<th>Telephone</th>
</tr>
</thead>
<tbody>
<?php foreach($query as $row) { ?>
<tr>
<td><a href="your_url_page_here.php"><?php echo $row["location"]; ?></a></td>
<td><?php echo $row["address"]; ?></td>
<td><?php echo $row["telephone"]; ?></td>
</tr>
<?php } ?>
</tbody>
</table>