当PHP通过Submit按钮发送数据(表名)时,总是显示最后创建的表


PHP when sending data (table name) via a Submit button always shows the last table created

所以,我对php有点陌生,我需要将表名发送到另一个php文件这是我已经拥有的代码:

<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>

现在我只需要输入按钮工作,当我提交它时,我应该发送到另一个php文件,只是:

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

但是它总是给我最后创建的表,所以如果我创建了3个表

  • 表B
  • 表C

$classname总是显示"Table C"。

英文不好意思,这不是我的第一次。

这是因为代码是在循环中执行的。当您按enter键时,循环完成,唯一可用的表是最后创建的表c。您可以使用表数组来存储创建的每个表字符串。检索它,然后附加一个事件