Home >Backend Development >PHP Tutorial >如何用php 循环 option

如何用php 循环 option

WBOY
WBOYOriginal
2016-06-06 20:35:502055browse

<code><?php mysql_connect('localhost','root','');
mysql_select_db('test');
mysql_query('set name uft8');
$sql='select * from tset';
$result=mysql_query($sql);


?>



<?php <?php while($row=mysql_fetch_array($result)):
菜单:<select>
<option value="1"><?php $row['username']?></option>
<option value="2">选项二</option>
<option value="3">选项三</option>
      

<?php endwhile?>


?>
</code>

这样好像不行 该咋循环捏

回复内容:

<code><?php mysql_connect('localhost','root','');
mysql_select_db('test');
mysql_query('set name uft8');
$sql='select * from tset';
$result=mysql_query($sql);


?>



<?php <?php while($row=mysql_fetch_array($result)):
菜单:<select>
<option value="1"><?php $row['username']?></option>
<option value="2">选项二</option>
<option value="3">选项三</option>
      

<?php endwhile?>


?>
</code>

这样好像不行 该咋循环捏

如何用php 循环 option

<?php 标签不能嵌套吧

多了一个<?php

<?php $row['username']?> 修改成 <?php echo $row['username']?>

<code><?php mysql_connect('localhost','root','');
mysql_select_db('test');
mysql_query('set name uft8');
$sql='select * from tset';
$result=mysql_query($sql);


?>

菜单:<select>

    <?php while($row=mysql_fetch_array($result)):?>
    <option value="<?=$row['id']?>">=$row['username']?></option>
    <?php endwhile?>

 </select>
</code>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn