If a dynamic select box has no data, default to empty...?

I have a select box that is filled with dynamic data (code below).  If there is no data in the record, I need the box to be empty...right now it has the first record in the record source.

 <select name="raceFastestLap" id="raceFastestLap">
          <?php
do {  
?>
          <option value="<?php echo $row_alldrivers['racerID']?>"<?php if (!(strcmp($row_alldrivers['racerID'], $row_Recordset1['racerID']))) {echo "selected=\"selected\"";} ?>><?php echo $row_alldrivers['racerNickName']?></option>
          <?php
} while ($row_alldrivers = mysql_fetch_assoc($alldrivers));
  $rows = mysql_num_rows($alldrivers);
  if($rows > 0) {
      mysql_data_seek($alldrivers, 0);
        $row_alldrivers = mysql_fetch_assoc($alldrivers);
  }
?>
        </select>
Kevin SmithAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

theGhost_k8Database ConsultantCommented:
I think before looping only you can manually put the blank entry!
    <option value="" ....
0
nasirbestCommented:
use "while" loop instead of "do"

and additionally on empty record-set if you want to show something more meaning full rather then empty select box like "No record found" etc.. then enclose this loop into if statement. like
<select name="raceFastestLap" id="raceFastestLap">
<?php 
$rows = mysql_num_rows($alldrivers);

if ($rows > 0) {
    while ($row_alldrivers = mysql_fetch_assoc($alldrivers)) { 
?>
    <option value="<?php echo $row_alldrivers['racerID']?>"<?php if (!(strcmp($row_alldrivers['racerID'], $row_Recordset1['racerID']))) {echo "selected=\"selected\"";} ?>><?php echo $row_alldrivers['racerNickName']?></option>
<?php 
    } 
} else {
?>
    <option value="">No record found</option>
<?php
}

if($rows > 0) {
    mysql_data_seek($alldrivers, 0);
    $row_alldrivers = mysql_fetch_assoc($alldrivers);
}
?>
</select>

Open in new window

0
Kevin SmithAuthor Commented:
The code above seems to just be removing the first record from the dynamic list...?
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

nasirbestCommented:
there may be a row "before" code (which you have placed in question) like

mysql_fetch_assoc($alldrivers);

remove it, it is not needed if you are using my code. there must be not such line "before" of my code.
0
Kevin SmithAuthor Commented:
removed it from the code, still doesn't work.  is there a way to leave it where it's at and remove it from your code?  the code that does that delivers data to other parts of the page.
0
nasirbestCommented:
OK, leave this that line.

and add this one before while loop

    mysql_data_seek($alldrivers, 0);


like
<select name="raceFastestLap" id="raceFastestLap">
<?php 
$rows = mysql_num_rows($alldrivers);

if ($rows > 0) {
    mysql_data_seek($alldrivers, 0);
    while ($row_alldrivers = mysql_fetch_assoc($alldrivers)) { 
?>
    <option value="<?php echo $row_alldrivers['racerID']?>"<?php if (!(strcmp($row_alldrivers['racerID'], $row_Recordset1['racerID']))) {echo "selected=\"selected\"";} ?>><?php echo $row_alldrivers['racerNickName']?></option>
<?php 
    } 
} else {
?>
    <option value="">No record found</option>
<?php
}

if($rows > 0) {
    mysql_data_seek($alldrivers, 0);
    $row_alldrivers = mysql_fetch_assoc($alldrivers);
}
?>
</select>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Kevin SmithAuthor Commented:
Still having issues with this, but went in another direction anyway.  Thanks!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.