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

如何用php 循环 option

WBOY
Release: 2016-06-06 20:35:50
Original
2035 people have browsed it

<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>
Copy after login
Copy after login

这样好像不行 该咋循环捏

回复内容:

<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>
Copy after login
Copy after login

这样好像不行 该咋循环捏

如何用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>
Copy after login
Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template