簡體   English   中英

使用PHP動態顯示選項值

[英]Dynamically displaying option values using PHP

我是PHP的新手,已經創建了一個非常基本的HTML表單。 如您在我的表格中所見,選項值都是手工完成的(還有更多,我只是簡化了這個示例)。 我想要的是僅使用PHP動態生成這些文件,因此我實際上每年都必須添加等。

我已經做了一些搜索,但似乎找不到確切的答案,以為我會在這里問。 盡管我不確定如何執行此操作,但根據我的收集,我需要創建一個查詢並以某種方式回顯選項值。

SELECT gameYear from games

我猜上面的將是正確的查詢,因為所有表格所需的都是表中的bookYear?

<form id = "gameYear" method="get" action="result.php">
<label> 
    Game Year
    <select name="gameYear">
       <option value="2000">2000</option>
       <option value="2001">2001</option>
       <option value="2002">2002</option>
    </select>
</label>
   <input type = "submit" name="search" value = "Search">
</form>

謝謝,任何幫助/指導表示贊賞。

<form id = "gameYear" method="get" action="result.php">
<label> 
Game Year
<select name="gameYear">
<option value=''>--Select Year--</option>
<?php
$link = mysqli_connect("localhost", "my_user", "my_password", "world");
$SqlResult = mysqli_query($link, "SELECT gameYear from games");
while($Row = mysqli_fetch_array($SqlResult))
{
  ?>
  <option value="<?php echo $Row['gameYear'] ?>"><?php echo $Row['gameYear'] ?></option>
}
?>
</select>
</label>
<input type = "submit" name="search" value = "Search">
</form>
<?php $sql = "SELECT gameYear from games order by gameYear ASC";
    $result = mysql_query($sql, $connection) or die ("Couldn't perform query $sql <br />".mysql_error()); ?>


<form id="gameYear" method="get" action="result.php">
<label>Game Year
<select name="gameYear">
<?php while($row = mysql_fetch_array($result)){ ?>                        
<option value="<?php echo $row['gameYear'] ?>"><?php echo $row['gameYear']?></option>
<?php } ?>
</select>
</label>
<input type = "submit" name="search" value = "Search">
</form>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM