【问题标题】:How do I post a row of data to another script? [duplicate]如何将一行数据发布到另一个脚本? [复制]
【发布时间】:2013-06-25 18:28:24
【问题描述】:
<?php 
    $pvp=mysql_query("SELECT * FROM characters ORDER BY level DESC");
echo "<table><tr><th>Character</th><th>Level</th><th>Tribe</th></tr>";
while ($row = mysql_fetch_array($pvp)) {
    echo "<tr><td>".($row['charname'])."</td><td>".($row['level'])."</td><td>".($row['tribe'])."</td><td><form action='/scripts/pvp.php' method='post'><input type='submit' name='pvp' value='Battle!'></form></td></tr>";
}
echo "</table>";
?>

在这个脚本中,我循环遍历一个数组并显示存储在一个变量 ($pvp) 中的所有数据。我想在每一行的末尾添加一个输入按钮,允许我将该特定行发布到另一个页面以在另一个脚本中使用。我该怎么做?

【问题讨论】:

标签: php sql loops input


【解决方案1】:

while() 循环内部:

echo "<tr><td>".($row['charname'])."</td>";
echo "<td>".($row['level'])."</td><td>".($row['tribe'])."</td>";
echo "<td><form action='/scripts/pvp.php' method='post'>";
echo "<input type=hidden name='tribe' value='".$row['tribe']."'>";
echo "<input type=hidden name='charname' value='".$row['charname']."'>";
echo "<input type=hidden name='level' value='".$row['level']."'><input type='submit' name='pvp' value='Battle!'></form></td></tr>";

【讨论】:

  • 将隐藏的输入添加到我的循环中会破坏我的当前页面。
  • 以前,我的脚本 - 无表单 - 将显示一个包含 3 行信息以及标题的表格。当我将其添加到脚本时,页面显示为空白。
  • 哦,是的,忘记删除多余的“(”。现在试试。
  • 效果很好,谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-08-28
  • 1970-01-01
  • 1970-01-01
  • 2015-08-23
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多