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!

 

Link to comment
Share on other sites

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