Jahed Hussain
Jahed Hussain

Reputation: 113

Drop Down Box Contains Empty Spaces/Values

I am grabbing some values from my database and putting them in a drop down box for users to select. I have Spry Validations (inbuilt with dreamweaver) and so at least one option has to be chosen before submitting its data. For some weird odd reason, i have a blank value after each option which does not make sense as my database does not contain any blank fields.

    <?php 

$id = $_GET['election'];

$sql="SELECT party1, party2, party3 FROM elections WHERE status = 'in_progress' AND election_id = '$id'";

$result=mysql_query($sql);

$options="";
$party2="";
$party3="";

while ($row=mysql_fetch_array($result)) {

    $id=$row["party1"];
    $thing=$row["party1"];
    $options.="<OPTION VALUE=\"$id\">".$thing;

    $id=$row["party2"];
    $thing=$row["party2"];
    $party2.="<OPTION VALUE=\"$id\">".$thing; 

    $id=$row["party3"];
    $thing=$row["party3"];
    $party3.="<OPTION VALUE=\"$id\">".$thing;
}
  ?>

my form looks like this:

    <form action="" method="post">

    <span id="spryselect1">
    <label for="vote">Vote:</label>
    <select size="1">
        <option selected="selected">Choose</option>
        <option value="1"><?=$options?></option>
        <option value="2"><?=$party2?></option>
        <option value="3"><?=$party3?></option>
</select>
    <span class="selectRequiredMsg">Please select an item.</span></span>

    <input name="" type="submit" value="Vote" />
  </form>

does anyone know why i keep getting blank values? I have attached an image to show you what i mean...empty drop down values

Upvotes: 0

Views: 1115

Answers (1)

pjumble
pjumble

Reputation: 16960

You're adding an option tag into the variables:

$options.="<OPTION VALUE=\"$id\">".$thing;

but you're also wrapping the variable in an option tag while outputting:

<option value="1"><?=$options?></option>

The result will be:

<option value="1"><OPTION VALUE="..">...</option>

which gives the empty tag.

Upvotes: 1

Related Questions