繁体   English   中英

来自 DB 列值的 PHP 下拉菜单

[英]PHP Dropdown Menu from DB column values

我的起点

我的 php

<?php

mysql_select_db("$db") or die(mysql_error());

$sql = "SELECT kpi FROM pin_kpi_types";
$query = mysql_query($sql);

echo '<select name="KPI" style="width: 400px">';
while ($row = mysql_fetch_assoc($query)) {
    echo '<option>'.$row['KPI'].'</option>';
}
echo '</select>';

?>

我当前需要手动输入的标签/输入法。

我想要做的是从表中提取查询以选择唯一可用的 KPI 类型。

这是现在工作。

<p>
  <label for="KPIType" id="preinput">Choose KPI Type: </label>
  <input type="text" name="kpi_type" required placeholder="Lead" id="inputid" />
</p>

我以前在哪里


编辑; 不幸的是,Lucky 发布的答案并没有安静地帮助我,但它以正确的方式引导我。

我现在有重复的字段? 它没有将值发布到数据库中。 任何一个。

这是一个截图...

http://s30.postimg.org/o1c2l9yr5/Untitled.png

有人可以引导我朝着正确的方向走我出错的地方吗? :)

预先感谢您的任何帮助。

<?php
    include('db.php');
        $select=mysql_query("SELECT * FROM pin_kpi_types");
        $i=1;

    while( $userrow=mysql_fetch_array($select) )
        {
        $kpi_id     =$userrow['KPI_ID'];
        $kpi        =$userrow['KPI'];
?>
<style>
#CreateStatusTypeFORM label {display: inline-block;width: 10em; text-align: right;padding-right: 0.5em;}
</style>

    <div id="CreateStatusTypeFORM">
    <form action="insert.php" method="post" name="insertform">
<p>
  <div align='center'><label for="StatusColor" id="preinput">Choose A Color: </label>
    <ui-colorpicker ng-model="targetColor"></ui-colorpicker></div>
  <input type="hidden" name="pinstatus_color" value="{{targetColor}}" id="inputid" />
</p>    
<p>
  <label for="StatusName" id="preinput">Set Status Name: </label>
  <input type="text" name="pinstatus_type" required placeholder="Come Back" id="inputid"/>
</p>
<p>
  <label for="StatusName" id="preinput">Available KPI Types: </label>
   <select name="<?php echo $kpi; ?>" style="width: 237px">
    <option name="KPI" required id="inputid" value="<?php echo $kpi; ?>"><?php echo $kpi; ?></option>
  </select>
</p>
<?php } ?>
  <input type="submit" name="send" value="Submit" id="inputid1"  />
</p>
</form>

我现在在哪里


这就是我所在的地方。 我现在可以得到正确的下拉列表,而无需一遍又一遍地重复它。 不过,现在我不能去张贴实际所选KPI的DB 其他所有内容都将数据提交到数据库,但KPI_type option.

<style>
.StatusForm {padding-left:75px;}
.CreateStatusTypeFORM {padding:25px;border-style:solid; border-color:solid black; width: 500px;background-color:#C4C4C4;}
#CreateStatusTypeFORM label {display: inline-block;width: 100em;}
#CreateStatusTypeFORM input {border-color:solid black;}
#CreateStatusTypeFORM input[type=text] {padding:5px; border:1px solid #666; -webkit-border-radius: 5px; border-radius: 5px;}
</style>
<div class='StatusForm'>
    <div class="CreateStatusTypeFORM">
    <H3> ADD New Status </H3>
    <form action="insert.php" method="post" name="insertform">
<p>
  <label for="StatusColor" id="preinput">Choose A Color: </label>
    <ui-colorpicker ng-model="targetColor"></ui-colorpicker>
  <input type="hidden" name="pinstatus_color" value="{{targetColor}}" id="inputid" required placeholder=""/>
</p>    
<p>
  <label  for="StatusName" id="preinput">Set Status Name: </label>
  <input type="text" name="pinstatus_type" required placeholder="" id="inputid"/>
</p>
<p>
  <label for="KPI" id="preinput">Available KPI Types: </label>
   <select>
    <?php
    include('db.php');
        $select2=mysql_query("SELECT * FROM pin_kpi_types ORDER BY KPI_ID DESC");

    while( $userrow=mysql_fetch_array($select2) )
        {
        $kpi            =$userrow['KPI'];
        $kpi_id         =$userrow['KPI_ID'];        

?>
<option name="kpi_type" required id="inputid" value="<?php echo $kpi; ?>"><?php echo $kpi; ?></option><?php } ?>
  </select>
</p>
  <input type="submit" name="send" value="Submit" id="inputid1"  />
</p>
</form>
</div>
</div>

这是插入功能。

<?php
    ob_start();
        include("db.php");

        if(isset($_POST['send'])!="")
            {
                $pinstatus_type     =mysql_real_escape_string($_POST['pinstatus_type']);
                $kpi_type       =mysql_real_escape_string($_POST['kpi_type']);
                $pinstatus_color        =mysql_real_escape_string($_POST['pinstatus_color']);
                $update         =mysql_query("
                                            INSERT INTO pin_status_types(
                                                                pinstatus_type,
                                                                kpi_type,
                                                                pinstatus_color,
                                                                created
                                                                )
                                                        VALUES(
                                                                '$pinstatus_type',
                                                                '$kpi_type',
                                                                '$pinstatus_color',
                                                                now()
                                                                )
                                                ");

                if($update)
                {
                $msg="Successfully Updated!!";
                    echo "<script type='text/javascript'>alert('$msg');</script>";
                        header('Location:index.php');
                }
                else
                {
                $errormsg="Something went wrong, Try again";
                    echo "<script type='text/javascript'>alert('$errormsg');</script>";
                }
            }
        ob_end_flush();
?>
mysql_select_db("$db") or die(mysql_error());

$sql = "SELECT kpi FROM pin_kpi_types";
$query = mysql_query($sql);
echo '<label for="KPIType" id="preinput">Choose KPI Type: </label>';
echo '<select name="KPI" style="width: 400px"  required id="inputid">';
echo '<option value=''>Lead</option>';
while ($row = mysql_fetch_assoc($query)) {
echo '<option value='.$row['KPI'].'>'.$row['KPI'].'</option>';
}
echo '</select>';
                        <?php
                        include 'config.php';
                        $sql_states=mysqli_query($conn,"SELECT * FROM master_states");
                        ?>
                        <section Name="state_name">
                            <option value="">section1</option>
                            <option value="">section2</option>

                        </section>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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