在从mysql加载的列表框中插入选项

时间:2014-01-14 15:13:53

标签: php html mysql listbox

大家好我已经用mysql数据库创建了一个列表框,现在我想让用户插入一个不存在的选项。谁能告诉我怎么做?我想创建一个表单或其他东西,允许用户为新选项引入一个值,然后它出现在列表框中并转发获取值以保存在mysql数据库中。

最好的问候。

<html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="keywords" content="jquery,ui,easy,easyui,web">
    <meta name="description" content="easyui help you build your web page easily!">
    <link rel="stylesheet" type="text/css" href="jeasyui_src/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="jeasyui_src/themes/icon.css">
    <link rel="stylesheet" type="text/css" href="jeasyui_src/demo/demo.css">
    <script type="text/javascript" src="jeasyui_src/jquery.min.js"></script>
    <script type="text/javascript" src="jeasyui_src/jquery.easyui.min.js"></script>
    </head>
    <body>
     <script language='Javascript' type='text/javascript'>
         function edit_file()
         {
             $("#button_file").css("visibility" , "hidden");
             $("#file_new").css("visibility" , "visible");
         }
         </script>
     <h3>Coloque aqui a sua revisao tecnica:</h3></br>   
<?php
    include_once 'acess_db.php';
    $query = "select * from faqs_treeview where level=1 order by category_title";
    $result = mysql_query($query);
?>
    <table border='0'>
    <tr>
    <td> 
    <form method="POST" name="form1" id="t1" style="visibility: visible;"> 
    <select name="cat_1" style="visibility: visible;">
    <option>Selecione a categoria</option>
<?php
while($row = mysql_fetch_array($result))
{
    $id = $row["id_category"];
    $name = $row["category_title"];
    echo "<option value='$id'>".$name."</option>";
}
?>
</select>
<input type="submit" name="submit1" onclick="open2();">
</form>

 <?php
 if(isset($_POST["cat_1"]))
 {
// echo $_POST["cat_1"];
 $id2 = $_POST["cat_1"];
 $query1 = "select * from faqs_treeview where high_level=$id2";
 $result1 = mysql_query($query1);
 $form_visible = "visible";
 }
 else
 {
     $form_visible = "hidden";
 }
 ?>
    </td>
    <td>
<form method="POST" name="myform2" id="t2" style="visibility: <?= $form_visible ?>"> 
    <select name="cat_2" >
    <option>Selecione a  sub-categoria</option>
<?php
while($row1 = mysql_fetch_array($result1))
{
    $id = $row1["id_category"];
    $name = $row1["category_title"];
    echo "<option value='$id'>".$name."</option>";
}
?>
</select>
<input type="submit" name="submit2" onclick="open3();">
<input type="hidden"  name="cat_1" value="<?= $_POST["cat_1"]?>">
</form>
    </td>
 <?php
 //echo $_POST["cat_2"];
 if(isset($_POST["cat_2"]) )
 {
 $id3 = $_POST["cat_2"];
 $query2 = "select * from faqs_treeview where high_level=$id3";
 $result2 = mysql_query($query2);
  $form_visible = "visible";
 }
 else
 {
     $form_visible = "hidden";
 }
 ?>
<td>

<form method="POST" name="myform3" id="t3" style="visibility: <?= $form_visible ?>"> 
    <select name="cat_3" >
    <option>Selecione a  sub-sub-categoria</option>
<?php
while($row2 = mysql_fetch_array($result2))
{
    $id = $row2["id_category"];
    $name = $row2["category_title"];
    echo "<option value='$id'>".$name."</option>";
}
?>
</select>
<input type="submit" name="submit3" onclick="closeall();">
<input type="hidden"  name="cat_1" value="<?= $_POST["cat_1"]?>">
<input type="hidden"  name="cat_2" value="<?= $_POST["cat_2"]?>">
</form>
</td>
    </tr>
    </table>

1 个答案:

答案 0 :(得分:0)

您可以使用AJAX。我看到你使用jQuery,所以一个简单的get或post-request应该可以解决问题。

在这里:jQuery .get你会找到一些关于如何做到这一点的例子。将项目添加到数据库后,您可以使用jQuery将其添加到选择框中。