litebearer Posted July 7, 2010 Share Posted July 7, 2010 I have a form in which I populate a SELECT field from my database. There are 55 records that match the criteria in the data base; however, the form select only displays 27 of the records (See PAGE 1 - below) . Yet, when I run a simple echo of the same result set ALL the proper records show (See PAGE 2 - below). PAGE 1 <!doctype html public "-//w3c//dtd html 3.2//en"> <html> <head> <title></title> </head> <body bgcolor="#ffffff" text="#494949" link="#6a1a22" vlink="#6a1a22" alink="#6a1a22"> <?PHP include('db.php'); $father_query = "SELECT * from main where gender='1' ORDER BY lastname, firstname"; $father_result = mysql_query($father_query); ?> <form action="" method="post"> <select name="father_ld"> <option value="0">Unknown</option><br> <?PHP while($father_row = mysql_fetch_array($father_result)){ ?> <option value="<?PHP echo $father_row['id']; ?>><?PHP echo $father_row['lastname']. ", ". $father_row['firstname']; ?></option><br /> <?PHP } ?> </select> </form> </body> </html> PAGE 2 <?PHP session_start(); include('db.php'); $father_query = "SELECT * from main where gender='1' ORDER BY lastname, firstname"; $father_result = mysql_query($father_query); $i=1; while($father_row = mysql_fetch_array($father_result)){ echo $i . " = " . $father_row['lastname']. ", ". $father_row['firstname'] . "<br />"; $i++; } ?> Help! Link to comment https://forums.phpfreaks.com/topic/207005-displaying-result-set-in-a-form-select-field/ Share on other sites More sharing options...
tomtimms Posted July 7, 2010 Share Posted July 7, 2010 Try this. <option value="<?PHP echo $father_row['id']; ?>"><?PHP echo $father_row['lastname'] . "," . $father_row['firstname']; ?></option> Link to comment https://forums.phpfreaks.com/topic/207005-displaying-result-set-in-a-form-select-field/#findComment-1082422 Share on other sites More sharing options...
litebearer Posted July 7, 2010 Author Share Posted July 7, 2010 Thank you!!! I didn't see the missing quotes Link to comment https://forums.phpfreaks.com/topic/207005-displaying-result-set-in-a-form-select-field/#findComment-1082429 Share on other sites More sharing options...
myrddinwylt Posted July 7, 2010 Share Posted July 7, 2010 If you wish to make it a bit easier to read, try the following <?php session_start(); include('db.php'); $father_query = "SELECT * from main where gender='1' ORDER BY lastname, firstname"; $father_result = mysql_query($father_query); $i=1; $options = null; while($father_row = mysql_fetch_array($father_result)){ $options .= '<option value="' . $father_row['id'] . '">' . $father_row['lastname'] . ',' . $father_row['firstname'] . '</option>'; $i++; } if($options == null) { $options = '<option value="0"> --- NO OPTIONS AVAILABLE --- </option>'; } else { $options = '<option value="0">Unknown</option>' . $options; } echo '<select>' . $options . '</select>'; ?> Link to comment https://forums.phpfreaks.com/topic/207005-displaying-result-set-in-a-form-select-field/#findComment-1082432 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.