Reputation: 33
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>
Upvotes: 0
Views: 78
Reputation: 1042
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>
Upvotes: 0
Reputation: 219834
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.
Upvotes: 1
Reputation: 3867
<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>
Upvotes: 0