duansan9435 2016-11-13 08:06
浏览 65
已采纳

PHP通过提交按钮发送数据(表名)时始终显示最后创建的表

So, im a little new to php and i need to send a table name to another php file this is the code i already have:

<form action="clases.php" method="GET">

        <?php
         $result= mysql_query('SHOW TABLES', $conn) or die ('cannot show tables');
    while($tablename = mysql_fetch_array($result)){
        $a=0;
        $table = $tablename[$a];




       echo '<table cellpadding="0" cellspacing="0" class="db-table">';
       echo '<tr>';


        echo '<td>',$table,'<input type="hidden" name="Class" value="' . $table . '" />';
        echo '</td>';
        echo "<td><input type='submit' name='Entrar' value='Enter'></td>";
        echo "<td><input type='submit' name='Eliminar' value='Delete'></td>";
        echo '</tr>';
        echo '</table><br />';
        ++$a;
      }
        ?>
</form>

Right now i just need the Enter button working, when i submit it i should send to another php file with just:

<?php $classname = $_GET['Class']; echo $classname; ?>

But it always gives me the last table i created, so if a have 3 tables created

  • Table A
  • Table B
  • Table C

the $classname always shows "Table C".

Sorry about the english, its not my first lenguaje.

  • 写回答

1条回答 默认 最新

  • doumiebiao6827 2016-11-13 08:09
    关注

    It is because the code is executed in a loop. By the time you press enter the loop is complete and the only available table is the last one created which it table C.You can use an array of tables to store every table string created.Retrieve it and then attach an event

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 有人会搭建GPT-J-6B框架吗?有偿
  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名