|  | Posted by dombi on 07/01/06 02:48 
On 2006-06-30 18:30:16 -0700, dombi <dombi@cox.net> said:
 > My website is based on some CMS sytem. From there I am getting a string
 > value passed into php, which I would like to compare to two possible
 > choices. The result of this comparison would be used to set a dropdown
 > menus selected option. For some reason I cannot do this right. I think
 > it might have something to do with foreign characters that I am using,
 > althogh I am not 100% sure...
 >
 > Here is what I have.
 >
 > $localvar = array("{string variable from CMS}");      // this comes
 > from the CMS and is either "kereskedő" or "magánszemély"
 > $choices = array("kereskedő", "magánszemély");  // this is just a
 > preset array with the two possibilities
 >
 > echo '<select name="yourtype">';                         // setting up
 > the pulldown menu
 > 	foreach ($choices as $value) {
 > 		echo "<option value=\"" . $value . "\"";
 > 		if ( $value === $localvar[0] ) echo " selected";
 > 		echo ">" . $value .  "</options>";
 > 	}
 > echo '</select><br />';
 >
 >
 > If I echo $localvar[1] out I do get either 'kereskedő" or
 > "magánszemély", but when it passed through the conditional, it always
 > fails. What could be going on here?
 >
 >
 > Thanks in advance!
 >
 > dombi
 
 Alright... this works...
 
 $localvar = array("{string variable from CMS}");
 $choices = array("kereskedő", "magánszemély" ); //something screwy with
 the character encoding between the database and this form...
 
 echo '<select name="yourtype">';
 foreach ($choices as $value) {
 echo "<option value=\"" . $value . "\"";
 if ( strlen(trim($value)) == strlen(trim($localvar)) ) echo " selected";
 echo ">" . $value .  "</options>";
 }
 echo '</select><br />';
  Navigation: [Reply to this message] |