I trying to make a select that should be post and contain all the votacoes from an user
<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>
Your <option>
needs to be in your loop:
<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>
You probably need to also add a unique ID as the value
attribute for each <option>
for this to be truly useful.
<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>
try this
<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>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.