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

Link to comment
Share on other sites

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.