开发者

Dynamic drop down list!

I have edited the question as what I said before was two pieces of code together.

I have the following code:

        $f = "SELECT * FROM ".TBL_FIXTURES." WHERE compname =  '$_POST[league]' AND home_user = '$_SESSION[username]' ORDER BY away_user";
    $fixtures = mysql_query($f);
    ?>
    <?
    while( $row = mysql_fetch_assoc($fixtures))
    {
        extract($row);
        $info = explode("_",$row[compname]);    
        ?>  


        <select name="hu" class="combo">
            <option value="<? echo $home_user ?>"><? echo $home_user?></option>
        </select>       
        <select name="au" class="combo">
        <?php
        while( $row = mysql_fetch_assoc($fixtures))
        {
            $u=$row['away_user'];
            echo "<option value=\"$u\">$u</option>";
        }
        ?>
        </select>
        <?

    }   
    ?>

As you can see, there are two while loops. But the first value from the dropdown list for away_user is missing. If i remove the first loop, it appears but the drop down for home_user disappe开发者_如何学Pythonars. How can i get around this?

THanks


The problem is that in your second loop you call mysql_fetch_assoc($fixtures) so you move on to the second record before using the away_user field from the first record. Two options I can think of are:

Create the first option before the loop

    <select name="au" class="combo">
    <?php
    $u=$row['away_user'];
    echo "<option value=\"$u\">$u</option>";

    while( $row = mysql_fetch_assoc($fixtures))
    {
        $u=$row['away_user'];
        echo "<option value=\"$u\">$u</option>";
    }
    ?>
    </select>

Change the loop to a do while loop

    <select name="au" class="combo">
    <?php
    do
    {
        $u=$row['away_user'];
        echo "<option value=\"$u\">$u</option>";
    } while( $row = mysql_fetch_assoc($fixtures))
    ?>
    </select>



does it give an error? it seems like you are missing a bracket (") in th end of this line :

echo"<div align=\"center\"> <table cellspacing=\"10\" style='border: 1px dotted' width=\"450\" bgcolor=\"#eeeeee\">


I'm not sure why you are also printing a table... but you output </select> in the loop, that's the problem.

You should do

echo '<select>';
while (....)
     {
     echo '<option>'.$u.'</option>';
     }
echo '</select>';

<table code here>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜