gpt4 book ai didi

php - 我想选择一个表并使用我选择的表中的相同数据创建一个表

转载 作者:行者123 更新时间:2023-11-29 23:38:33 24 4
gpt4 key购买 nike

这些是我的问题:

  1. 我从两个下拉列表中选择的值将变回默认值当浏览器实现表单中的onchange函数时。

  2. 我想创建一个表,并且数据应该与我从第二个下拉列表中选择的表格。

这是我的代码

PHP

<?php
$connectDatabase = mysql_connect("localhost","root","") or die(mysql_error());
$tables = array();
if(isset($_POST['select_db']))
{ // if its submitted
$select_db = $_POST['select_db'];
$mysql_select_db = mysql_select_db($select_db,$connectDatabase);
$drop_table = mysql_query("DROP TABLE pdf_table",$connectDatabase);
$query = "SHOW TABLES FROM $select_db";
$mysql_query = mysql_query($query,$connectDatabase);
while($row =mysql_fetch_assoc($mysql_query))
{
$tables[] = $row['Tables_in_' . $select_db]; // use associative instead
}
}
if(isset($_POST['select_table']))
{
$select_table = $_POST['select_table'];
$db = mysql_select_db($select_db,$connectDatabase);
$query_select = "Create Table pdf_table AS ( SELECT * FROM $select_table)";
$select_query = mysql_query($query_select,$connectDatabase);
}
?>

HTML 代码

 <form class="Search_Form" action="moduleindex.php" method="POST">
<select name="select_db" onchange="this.form.submit();">
<option disabled selected>Select Database</option>
<option>section_masterfile</option>
</select>
<select onchange="this.form.submit();" name="select_table">
<option disabled selected>Select Table</option>
<?php foreach($tables as $table): ?>
<option value="<?php echo $table; ?>"><?php echo $table; ?></option>
<?php endforeach; ?>
</select>
</form>

最佳答案

如果发布了某些值且值等于循环值,则在生成选项时在 foreach 循环中添加检查

  <select onchange="this.form.submit();" name="select_table">
<option disabled selected>Select Table</option>
<?php foreach($tables as $table){?>
<?php
$selected ="";
if(isset($_POST['select_table']) && $_POST['select_table'] == $table){

$selected = 'selected="selected"';


} ?>
<option value="<?php echo $table; ?>" <?php echo $selected ;?> ><?php echo $table; ?></option>
<?php }?>
</select>

关于php - 我想选择一个表并使用我选择的表中的相同数据创建一个表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26293455/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com