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

时间:2018-09-15 15:24:53

标签: php mysql database wordpress

看看我的插件,它在选择选项中显示了WordPress的所有表格。我想在此代码和屏幕截图选项中显示默认的一张桌子。

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

2 个答案:

答案 0 :(得分:0)

替换当前的sql代码:

const sampleInputs = [ '1,000', '10,000', '100,000', '1,000,000' ]

// + is a shortcut to convert to a number

// split at commas
const splitMethod = +sampleInputs[0].split(',').join('')

// match digits
const regexOne = +(sampleInputs[1].match(/\d/g) || []).join('')

// replace commas
const regexTwo = +sampleInputs[2].replace(/,/g, '')

// filter
const fi = +sampleInputs[3]
  .split('')
  .filter(n => n !== ',')
  .join('')


console.log('splitMethod', splitMethod)

console.log('regexOne', regexOne)

console.log('regexTwo', regexTwo)

console.log('filter', fi)

收件人:

$sql = "SHOW TABLES"; 

这将选择一个在 $ _ POST ['table_select']

中指定的表

答案 1 :(得分:0)

尝试一下 在本机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>";
    }
?>

相关问题