Page 1 of 1

Select option not working

Posted: Mon Jul 12, 2004 3:01 pm
by cdickson
I have used this code before and need to use it again. Why does the first one work and not the second one? I have pored over this for a couple of hours and can't find the difference.

I know that the database and field names are right because the first item in the second code comes up - it's just that the whole list (in this case of order numbers) won't appear. I would appreciate any help.

This works:

Code: Select all

<?php 
foreach ($_GET as $key => $value) { 
   $_GET[$key] = trim($value); 
} 
mysql_select_db($database_hschamber, $hschamber);
$query_rsCategories = "SELECT * FROM Category1 ORDER BY cat_desc1";
$rsCategories = mysql_query($query_rsCategories, $hschamber) or die(mysql_error());
$row_rsCategories = mysql_fetch_assoc($rsCategories);
$totalRows_rsCategories = mysql_num_rows($rsCategories);
?> 

<select name="searchCategory">
<?php
do {  
?>
<option value="<?php echo $row_rsCategories['cat_id1']?>"><?php echo $row_rsCategories['cat_desc1']?></option>
<?php
} while ($row_rsCategories = mysql_fetch_assoc($rsCategories));
  $rows = mysql_num_rows($rsCategories);
  if($rows > 0) {
      mysql_data_seek($rsCategories, 0);
	  $row_rsCategories = mysql_fetch_assoc($rsCategories);
  }
?>
</select>
This doesn't:

Code: Select all

<?php
foreach ($_GET as $key => $value) { 
   $_GET[$key] = trim($value); 
} 
mysql_select_db($database_mfm, $mfm);
$query_rsOrders = "SELECT * FROM orders ORDER BY order_no";
$rsOrders = mysql_query($query_rsOrders, $mfm) or die(mysql_error());
$row_rsOrders = mysql_fetch_assoc($rsOrders);
$totalRows_rsOrders = mysql_num_rows($rsOrders);
?>

<select name="selectOrders">
<?php
do {  
?>
<option value="<?php echo $row_rsOrders['order_no']?>"><?php echo $row_rsOrders['order_no']?></option>
<?php
} while ($row_rsOrders = mysql_fetch_assoc($row_rsOrders));
  $rows = mysql_num_rows($rsOrders);
  if($rows > 0) {
      mysql_data_seek($rsOrders, 0);
	  $row_rsOrders = mysql_fetch_assoc($rsOrders);
  }
?>
</select>

Posted: Mon Jul 12, 2004 3:07 pm
by feyd

Code: Select all

} while ($row_rsOrders = mysql_fetch_assoc($row_rsOrders));
is the problem. You want to pass $rsOrders to fetch_assoc...

Posted: Mon Jul 12, 2004 3:27 pm
by cdickson
Thanks, feyd! :D

On the same subject: If I am running the same query with dates, how do I get multiple dates to appear only once in the option value list that appears?

Code is:

Code: Select all

<select name="selectDate">
<?php
do {  
?>
<option value="<?php echo $row_rsDate['order_date']?>"><?php echo $row_rsDate['order_date']?></option>
<?php
} while ($row_rsDate = mysql_fetch_assoc($rsDate));
  $rows = mysql_num_rows($rsDate);
  if($rows > 0) {
      mysql_data_seek($rsDate, 0);
	  $row_rsDate = mysql_fetch_assoc($rsDate);
  }
?>
</select>

?>