Jump to content

Recommended Posts

I'm trying to populate a dropdown menu using data in a recordset I get from by querying my database. The data is being added to the menu, but for some reason an extra, blank, value is being inserted at the top. This means the menu appears blank when the user first sees it. If they click on it, the values appear, but it's not ideal. Site is http://humphreyb.stacnz.com/pages/bedlinen.php

 

The recordset is reused several times on the same page, so I have used mysql_data_seek. I thought this would ensure the data would appear okay, but no!

 

It works in Dreamweaver Live, but not when I test it in any live browser.

 

<select name="styleID" class="dropdownboxstyles" id="styleID">

            <?php

do {

?>

            <option value="<?php echo $rsStyle['styleID']; ?>"><?php echo $rsStyle['style']; ?></option>

            <?php } while ($rsStyle = mysql_fetch_assoc($style_query)) ?>

            <?php mysql_data_seek($style_query, 0); ?>

          </select>

 

 

Link to comment
https://forums.phpfreaks.com/topic/130799-initial-value-of-dropdown-menu-is-blank/
Share on other sites

Thanks, that works fine now. I don't quite understand why there would be a difference. I know that do while loops always execute at least once, but I thought given the syntax it would still work the same as a simple while loop. What's the reason for the difference?

Thanks, that works fine now. I don't quite understand why there would be a difference. I know that do while loops always execute at least once, but I thought given the syntax it would still work the same as a simple while loop. What's the reason for the difference?

 

The difference is the logic flow:

 

while:

1) Is condition true?

2) If yes, execute block and start over. If no, terminate loop

 

do-while:

1) Execute block

2) If condition is true, start over. Otherwise terminate loop.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.