Syntax help with dynamic drop down

I am struggling to get my syntax working for a dynamic drop down list

Here is what I have so far



<select name="companies">

<option value="-1" <?php if ($companies == -1) { ?>selected<?php } ?>>Select removal company to set prices of....</option>

<?php

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

echo '<option value="' . $row['id'] . '" if ($companies == $row['id']) { selected }> . $row['companyName'] . '</option>';

                				
}

echo '</select>';



Any help much appreciated

Thanks

Paul

Ah thanks Jake -much appreciated. Been a long day and nice to get this sorted before it ends:)

You have a bug in your code while using " " and ’ ', code hereunder should work correctly:

<select name="companies">
    <option value="-1" <?php if ($companies == -1) echo 'selected'; ?>>
        Select removal company to set prices of....
    </option>
    <?php
        while ($row = mysql_fetch_assoc($result)) {
            echo '<option value="' . $row['id'] . '" ';
            if ($companies == $row['id']) echo 'selected';
            echo '>' . $row['companyName'] . '</option>';
        }
    ?>
</select>

Regards,
Jake