[英]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.