0

我试图做出一个应该发布并包含来自用户的所有votacoes的选择

  <select name="votacao" size="1">

     <option>

       <?php
         $sql = "SELECT nome_votacao FROM votacoes WHERE user_id = $_SESSION['id']";
         $rs = mysql_query($sql);                       
         while($row = mysql_fetch_row($rs)) 
             echo $row['nome_votacao'];             
       ?>   

    </option>

</select>
4

3 回答 3

1

<option>需要在你的循环中:

<select name="votacao" size="1">


       <?php
         $sql = "SELECT nome_votacao FROM votacoes WHERE user_id = $_SESSION['id']";
         $rs = mysql_query($sql);                       
         while($row = mysql_fetch_row($rs)) {
             echo sprintf("<option>%s</option>\n", $row['nome_votacao']);  
         }      
       ?>   



</select>

您可能还需要添加一个唯一 ID 作为value每个属性的属性,<option>这样才能真正有用。

于 2012-05-26T16:02:30.087 回答
0
<select name="votacao" size="1"> 
       <?php 
         $sql = "SELECT nome_votacao FROM votacoes WHERE user_id = $_SESSION['id']"; 
         $rs = mysql_query($sql);                        
         while($row = mysql_fetch_row($rs))  
             echo "<option>".$row['nome_votacao']."</option>";              
       ?>
</select>
于 2012-05-26T16:01:42.777 回答
0

试试这个

<select name="votacao" size="1">

     <option>

       <?php
         $sql = "SELECT nome_votacao FROM votacoes WHERE user_id = $_SESSION['id']";
         $rs = mysql_query($sql);     
          foreach ($rs as $row)        
          { ?>

           <option> <?php echo $row['nome_votacao']; ?> </option>
       <? } ?>   

    </option>

于 2012-05-26T17:01:12.433 回答