简体   繁体   中英

show one table from mysql in select option?

look at my plugin it show all table from WordPress in select option. 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 = "SHOW TABLES"; 

to:

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

This will select one table specified in $_POST['table_select']

try this work on native 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>";
    }
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM