简体   繁体   English

在选择选项中显示来自mysql的一张表?

[英]show one table from mysql in select option?

look at my plugin it show all table from WordPress in select option. 看看我的插件,它在选择选项中显示了WordPress的所有表格。 I want to show default one table in option this my code and screenshot. 我想在此代码和屏幕截图选项中显示默认的一张桌子。

   <form id="wp_csv_to_db_form" method="post" action="">
                <table class="form-table"> 

              <tr valign="top"><th scope="row"><?php _e('Select 
               Database Table:','wp_csv_to_db'); ?></th>
              <td>
  <select id="table_select"  name="table_select" value="w<option name="" 
              value="wp_orderlist"></option>

                            <?php  // Get all db table names
                            global $wpdb;
                            $sql = "SHOW TABLES";
                            $results = $wpdb->get_results($sql);
                            $repop_table = isset($_POST['table_select']) 
                            ? $_POST['table_select'] : null;

       foreach($results as $index => $value) {
       foreach($value as $tableName) {                   
       ?><option name="<?php echo 
     $tableName ?>" value="<?php echo $tableName ?>" <?php 
     if($repop_table === $tableName) { echo 'selected="selected"'; } ?>> 
     <?php echo $tableName ?></option><?php
                      }
                      }
              ?>
             </select>


         [enter image description here][1]

Replace your current sql code: 替换当前的sql代码:

$sql = "SHOW TABLES"; 

to: 至:

$sql = "SHOW TABLES LIKE '" . $_POST['table_select'] . "'";

This will select one table specified in $_POST['table_select'] 这将选择$ _POST ['table_select']中指定的一个表

try this work on native php 在本地php上尝试这项工作

<select name="Kode" class="form-control">                                                        
<?php
    $konek = mysqli_connect("localhost","root","","dbsia");
    $query = "select * from tbpelajaran";
    $hasil = mysqli_query($konek,$query);
    while($data=mysqli_fetch_array($hasil)){
        echo "<option value=$data[kodepelajaran]>$data[kodepelajaran]</option>";
    }
?>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在一个 select 选项中获取选定值,并在此基础上,从 MySQL 表中获取数据,以相同形式显示另一个 select 选项 - How to get selected value in one select option and based on that, fetch data from MySQL table to show another select option in the same form 一个#id的多重选择选项以显示n个隐藏表 - multiple select option with one #id to show n hide table 显示来自mysql表的动态选择输入 - show a dynamic select input from mysql table 从一个MySQL请求中的另一个SELECT中选择一个表中的SELECT? - SELECT in a table from an other SELECT in one MySQL request? php, html mysql &#39;select * from table&#39; 解释为<select></select>选项框 - php, html mysql 'select * from table' interpreted as <select></select> option box 从 MySQL 中选择不同的选项 - Select distinct option from MySQL PHP MySQL - 如果使用 JOIN 查询在另一个表中存在记录,则将选择选项显示为已选择 - PHP MySQL - Show Select Option as selected If Record exist in another table using JOIN Query MySQL我可以从一个表还是另一个表中选择数据? - MySQL Can I Select Data from One table OR another Table? 如何用角度中的选择选项显示表格信息? - how to show table information with select option in angular? 如何从数据库中的数据获取数据到PHP MySQL中的一个选择选项到另一个选项? - How to get data from database to one select option to another option in PHP MySQL?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM