select box not repeating

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bruce88
Forum Newbie
Posts: 1
Joined: Thu Apr 01, 2010 3:38 am

select box not repeating

Post by bruce88 »

Hello I am able to populate a select box with items form a mysql table no problem. But what I am creating is a form that repeats the fields depending on the users selection on the previous page. This works no problem, except for the select box. It fails to show all the results. It only displays the second result I have tried many combinations of nested loops but with no joy. In stead of posting all the code I will post the code which generates the select box. Ideas are welcome.

Code: Select all

echo "<fieldset>\n";
		echo "<legend>\n";
		  echo "Products required for property\n";
		echo "</legend>\n";
//echo $productItemLoop;
		  $ProductIDArray = "ProductID$propNumber";
		  $ProductIDArrayBrackets = "[]";

while($nt1=mysql_fetch_array($result)){

	  $product_options_open = "<option value=\"$nt1[ProductID]\">";
	  $row_productType = $nt1['ProductType'];
	  $product_options_close = "</option>\n";	  
}


		  echo "<p>\n";
		  echo "Hold 'Ctrl' to select more than one product\n";
		  echo "<br />\n";
		    echo "<select multiple";
		      echo " ";
		      echo "name=";
		      echo "\"$ProductIDArray$ProductIDArrayBrackets\"";
		      echo " ";
		      echo "id=\"$ProductIDArray\" size=\"5\">\n";
			echo "$product_options_open\n";
			echo "$row_productType\n";
			echo "$product_options_close\n";
		      echo "</select>\n";
		  echo "</p>\n";
	      echo "</fieldset>\n";
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: select box not repeating

Post by Christopher »

You should use mysql_fetch_assoc().

Also when putting array elements or object properties in strings use braces -- for example "<option value=\"{$nt1['ProductID']}\">" or "<option value=\"{$obj->ProductID}\">".
(#10850)
Post Reply