如何从数据列表中获取值ID和显示标题?

时间:2018-12-30 12:15:59

标签: php mysql datalist

如何从数据列表中获取值ID和显示标题?

<input list="A" name="states" class="form-control states" placeholder="Select your state ..">

<datalist id="A" >

<?php
    $sql_states = $DB_con->prepare("SELECT * FROM US_STATES ORDER BY ID ");
    $sql_states->execute();
    while($row_states=$sql_states->fetch(PDO::FETCH_ASSOC))
    {
    ?>
        <option  value="<?php echo $row_states['ID'].$row_states['STATE_NAME'];?>" ></option>
    <?php
    } 
?>
</datalist>

1 个答案:

答案 0 :(得分:0)

在名为 data-id 的选项中创建自定义属性,然后可以借助jquery获取ID。让下面的代码。

Random R = new Random();
List<Image> images = new List<Image>();

private void Form1_Load(object sender, EventArgs e)
{
    images.Add(Image.FromFile(@"C:\Users\HP\source\repos\RockPaperScissors\RockPaperScissors\rock.png"));
    images.Add(Image.FromFile(@"C:\Users\HP\source\repos\RockPaperScissors\RockPaperScissors\paper.jpg"));
    images.Add(Image.FromFile(@"C:\Users\HP\source\repos\RockPaperScissors\RockPaperScissors\scissors.png"));

    btnRock.Click += All_Buttons_Click;
    btnPaper.Click += All_Buttons_Click;
    btnScissors.Click += All_Buttons_Click;
}

private void All_Buttons_Click(object sender, EventArgs e)
{
    picOption.Image = images[R.Next(images.Count)];
}