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

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

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!