Jump to content

unexpected behavior...while() appears to drop topmost array element.


rsleventhal

Recommended Posts

Hi all,

Please forgive the 'newbie-ness' of this question, but I think I'm getting unusual results from a fairly simple construct.

 

Basics: LAMP server, running Apache 2.0x and PHP 4.3.11. Not the most current, but that's what I've got Smile

 

I'm building a <select> dropdown list in a form. The data is coming from a MySQL table. The purpose of the form is to allow the admin of the site to email a list of users or a single user from the list.

 

Pertinent code:

$query = "Select `contact_email` from `contactlist` order by `contact_email` ASC";
   //$query = "Select `contact_email` from `contactlist`";
    $result = mysql_query( $query );
    $list = mysql_fetch_array( $result );
    $reccount = mysql_num_rows( $result ); 

 

The $reccount var is just my own reality check. It returns the correct/expected number of records as 17.

 

now the html/php integration for the form:

<select type="text" name="addressee" />
<option value="all">All contacts</option>
<?php

    // begin looping through to permit single selections of contacts

    while ($addr = mysql_fetch_array( $result ) )
    {
    $sendto = $addr['contact_email'];
      print "<option value=\"" . $sendto . "\">" . $sendto . "</option>\n";
    }


    ?>
</select> 

My issue is that while $reccount shows 17, I only get 16 records in the drop down list. The missing record is *always* the array element, meaning that if it's a naturally obtained order (db order), the first value is lost to the <select> construct. If I sort, the first sorted value is lost.

 

This appears to be different behavior to what while() should do, I think...

 

If anyone has any suggestions, I'd be very thankful.

 

Kind regards,

~Ray

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.