PHP添加按钮以查看整个记录MySQL的所有内容 [英] PHP Add button to view all the contents of entire record MySQL

查看:93
本文介绍了PHP添加按钮以查看整个记录MySQL的所有内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前,我正在运行一个查询,该查询将显示产品"表和与产品相关联的用户"的所有内容.它打印在桌子上.我想创建一个按钮,显示所有记录. 请注意,我只能只查看选定的记录..我将如何处理?

Currently I have a query running that brings up all the contents of the 'products' table and the 'user' associated with the products. It prints on a table. I want to create a button, that brings up the entire records. Please note that I must only be able to view the selected record only.. How would I go about this?

echo "<table border='1'>
<tr>
<th>user_id</th>
<th>user_name</th>
<th>selected_product</th>
while($row = mysqli_fetch_array($result, MYSQLI_ASSOC))


  echo "<td>" . $row['user_id'] . "</td>";
  echo "<td>" . $row['user_name'] . "</td>";
  echo "<td>" . $row['selected_product'] . "</td>";

因此,应该为每个返回的记录显示一个按钮.当我单击此按钮时,将出现另一个窗口,该窗口显示了全部内容(仅针对此记录)以及与之相关的用户. 该按钮如何知道与其关联的记录.

So a button should appear for each record that is returned as a result. When I click this button another window should appear which shows the entire contents (for this record only) and the user associated. How does the button know which record its associated with.

推荐答案

<a href="anotherpage.php?id=<?php echo $row['user_id']?>" ><button>View Details</button></a>

这将带您到另一个页面. 使用get方法将id转换为php变量.

This will take you to another page. Use get method tho get the id into php variable.

$userId = $_GET['id'];

现在使用sql查询为单个用户从数据库中获取所有数据.

And now use sql query to fetch all the data from the database for single user.

$userResult = mysql_query("SELECT * FROM userTable WHERE user_id = ".$userId);

这篇关于PHP添加按钮以查看整个记录MySQL的所有内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆