rsleventhal Posted August 21, 2007 Share Posted August 21, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/66039-unexpected-behaviorwhile-appears-to-drop-topmost-array-element/ Share on other sites More sharing options...
lemmin Posted August 21, 2007 Share Posted August 21, 2007 It is because you are putting the first row into $list. remove the line: $list = mysql_fetch_array( $result ); and you should be good. Quote Link to comment https://forums.phpfreaks.com/topic/66039-unexpected-behaviorwhile-appears-to-drop-topmost-array-element/#findComment-330269 Share on other sites More sharing options...
rsleventhal Posted August 21, 2007 Author Share Posted August 21, 2007 wow...that certainly makes sense! Thanks for the tip. I'll work it and will reply to this thread when [solved] Many many thanks, ~Ray Quote Link to comment https://forums.phpfreaks.com/topic/66039-unexpected-behaviorwhile-appears-to-drop-topmost-array-element/#findComment-330283 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.