dousheng3364 2016-02-05 14:37
浏览 52
已采纳

PHP表格列

So my PHP displays a MySQL table, I'm aware you can tyle these which I plan to. But as the image below shows, the add button adds another column. enter image description here

Is it possible to make the add button below the two columns update and delete? If so how can I do this. Here is my code, sorry for any errors or being messy, I'm still learning.

while ($record = mysql_fetch_array($myData)) {
  echo "<form action=usermanagement.php method=post>";
  echo "<tr>";
  echo "<td>" . "<input type=text name=id value=" . $record['ID'] . " </td>";
  echo "<td>" . "<input type=text name=rank value=" . $record['Rank'] . " </td>";
  echo "<td>" . "<input type=text name=username value=" . $record['Username'] . " </td>";
  echo "<td>" . "<input type=text name=password value=" . $record['Password'] . " </td>";
  echo "<td>" . "<input type=hidden name=hidden value=" . $record['ID'] . " </td>";
  echo "<td>" . "<input type=submit name=update value=update" . " </td>";
  echo "<td>" . "<input type=submit name=delete value=delete" . " </td>";
  echo "</tr>";
  echo "</form>";
}
echo "<form action=usermanagement.php method=post>";
echo "<tr>";
echo "<td><input type=text name=uid></td>";
echo "<td><input type=text name=urank></td>";
echo "<td><input type=text name=uusername></td>";
echo "<td><input type=text name=upassword></td>";
echo "<td>" . "<input type=submit name=add value=add" . " </td>";
echo "</form>";
echo "</table>";    
  • 写回答

3条回答 默认 最新

  • dongpin6941 2016-02-05 14:49
    关注

    Pay attention to the closing tags of the inputs.. the hidden inputs can be put anywhere in the table as they not being displayed:

    while($record = mysql_fetch_array($myData)) {
        echo '<form action=usermanagement.php method=post>
                  <tr>
                       <td>
                            <input type=text name=id value="' . $record['ID'] . '" />
                       </td>
                       <td>
                            <input type=text name=rank value="' . $record['Rank'] . '" />
                       </td>
                       <td>
                            <input type=text name=username value="' . $record['Username'] . '" />
                       </td>
                       <td>
                            <input type=text name=password value="' . $record['Password'] . '" />
                       </td>
                       <td>
                            <input type=hidden name=hidden value="' . $record['ID'] . '" />
                            <input type=submit name=update value=update />
                       </td>
                       <td>
                            <input type=submit name=delete value=delete />
                       </td>
                  </tr>
              </form>';
    }
    
    echo '<form action=usermanagement.php method=post>
              <tr>
                   <td>
                        <input type=text name=uid />
                   </td>
                   <td>
                        <input type=text name=urank />
                   </td>
                   <td>
                        <input type=text name=uusername />
                   </td>
                   <td>
                        <input type=text name=upassword />
                   </td>
                   <td colspan="2">
                        <input type=submit name=add value=add />
                   </td>
              </tr>
          </form>';
    

    Also, try stop using mysql_* functions as they being deprecated. Use PDO, mysqli_ or the MySQLi class instead.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记