Jump to content

Displaying result set in a form select field


litebearer

Recommended Posts

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!

 

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>';
?>

 

 

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.