繁体   English   中英

PHP表可链接列

[英]PHP table linkable column

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

暂无
暂无

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

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