PHP 表可链接列

标签 php mysql

您好,我有一个查询来列出所有用户,我希望能够单击用户名并转到用户信息页面,所以我的问题是如何将用户名传递给其他 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&ccedil&atildeo</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/

相关文章:

php - 如何在我的结构/环境中使用 GIT?

mysql - 如何在mysql中快速导入10gb的sql文件?

php - preg_replace 问题

php - 使用 PDO 转换我的开发后,代码无法正常工作

mysql - Tweepy 信息写入 MySQL - 文本被截断

MySQL 过程未执行

mysql - 如何在没有管理员权限的情况下使用 PHPMyAdmin 更改 mysql 中的时区

php - 如何将 $request 添加到构造方法中?

php - 如何修复 PHP : "A non well formed numeric value encountered" 中的此错误

php - 如何将这个php slugify函数重写到mysql?