您好,我有一个查询来列出所有用户,我希望能够单击用户名并转到用户信息页面,所以我的问题是如何将用户名传递给其他 php。
while($row = mysql_fetch_array($result)) {
echo "<tr>";
echo "<td><font color='white'>" . ++$i . "</font></td>";
echo "<td><a href='page2.php'><font color='white'>" . $row['1'] . "</font></a></td>";
echo "<td><font color='white'>" . $row['2'] . "</font></td>";
echo "<td><font color='white'>" . $row['3'] . "</font></td>";
echo "<td><font color='white'>" . $row['4'] . "</font></td>";
echo "</tr>";
}
表格很好,我只需要一种将选择的用户名传递到 page2.php 的方法。
提前致谢
编辑:
while($row = mysql_fetch_array($result)) {
echo "<tr>";
echo "<td><font color='white'>" . ++$i . "</font></td>";
echo "<td><a href='page2.php?nome='".$row['nome']."><font color='white'>" . $row['nome'] . "</font></a></td>";
echo "<td><font color='white'>" . $row['sexo'] . "</font></td>";
echo "<td><font color='white'>" . $row['idade'] . "</font></td>";
echo "<td><font color='white'>" . $row['diabetes'] . "</font></td>";
echo "</tr>";
}
page2.php:
include_once 'ligacao.php';
$name = $_GET['nome'];
echo "<table border='1' align='center'>
<tr>
<th><font color='white'>Registo</font></th>
<th><font color='white'>Name</font></th>
</tr>";
echo "<tr>";
echo "<td><font color='white'>" . ++$i . "</font></td>";
echo "<td><font color='white'>" . $name . "</font></td>";
echo "</tr>";
编辑2:
如何在页面中间并排对齐 2 个表格?
echo "<table border='1'>
<tr>
<th><font color='white'>Glicemia</font></th>
<th><font color='white'>Hidratos</font></th>
<th><font color='white'>Peso</font></th>
<th><font color='white'>Descrição</font></th>
<th><font color='white'>Timestamp</font></th>
</tr>";
while($row = mysql_fetch_array($result)) {
echo "<tr>";
echo "<td><font color='white'>" . $row['glicemia'] . "</font></td>";
echo "<td><font color='white'>" . $row['hidratos'] . "</font></td>";
echo "<td><font color='white'>" . $row['peso'] . "</font></td>";
echo "<td><font color='white'>" . $row['descricao'] . "</font></td>";
echo "<td><font color='white'>" . $row['time'] . "</font></td>";
echo "</tr>";
}
echo "<table border='1'>
<tr>
<th><font color='white'>Medicamento</font></th>
<th><font color='white'>Timestamp</font></th>
</tr>";
while($row = mysql_fetch_array($resultq)) {
echo "<tr>";
echo "<td><font color='white'>" . $row['medicamento'] . "</font></td>";
echo "<td><font color='white'>" . $row['time'] . "</font></td>";
echo "</tr>";
}
最佳答案
您可以将其作为 url 参数传递,并在 page2.php
中使用 $_GET
,例如:
...
"<td><a href='page2.php?username='".$row[1].">...</a>
...
和page2.php
$username = $_GET['username'];
更新:: 您的代码似乎有引号问题,请尝试更改为:
....
echo "<td><a href='page2.php?nome=" . $row['nome'] . "'><font color='white'>" . $row['nome'] . "</font></a></td>";
...
关于PHP 表可链接列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24602552/