ABCD
ABCD

Reputation: 138

Getting duplicate values from mysql_fetch_assoc in while

I'm stuck with while in php this is the part that makes problem and still returning duplicate rows. When I use select in phpmyadmin I get what I'm looking for. I think problem is with while. Can you look at it?

<td><select name='movie_type'> 
       <?php  

       $query = 'SELECT movietype_id, movietype_label FROM `movietype`';
       $result = mysql_query($query, $db) or die (mysql_error($db));

       while ($row = mysql_fetch_assoc($result)) {
            foreach ($row as $value) {
                echo '<option value="' . $row['movietype_id'] . '">';
                echo $row['movietype_label'] . '</option>';
            }
       }

       ?>
       </select></td>

Upvotes: 0

Views: 753

Answers (1)

anon
anon

Reputation:

You don't need to use foreach loop, just change your code to:

while ($row = mysql_fetch_assoc($result)){
    echo '<option value="' . $row['movietype_id'] . '">';
    echo $row['movietype_label'] . '</option>';
}

Upvotes: 4

Related Questions