I have an options value drop down and a switch to set the drop down. I am pulling the values from the mySQL server and trying to match the value to a value in the switch to set the drop down value.
echo $attribute;
$attributeArray = array("","Hello World");
$attribute2Array = array("","Hello World");
switch ((string)$attribute) {
case "$attribute2Array[1]":
$attributeArray[1] = "selected";
break;
}
echo "
<br>Attribute:<form method=post action=attributeEdit.php>
<select name=attribute>
<option value=$attribute2Array[0] $attributeArray[0]>$attribute2Array[0]</option>
<option value=$attribute2Array[1] $attributeArray[1]>$attribute2Array[1]</option>
</select></br>
";
The echo says the exact same thing as the switch does at least in the chrome web browser. So I have tried to replace the space in "Hello World" with "Hello&nb sp;World" (no space in the nb sp) but I cannot seem to get this to work. I have tried casting replacing and print_r etc. I have tried a if boolean comparison and it returns false. My method works except for values with spaces in them.
echo $attribute;
$attributeArray = array("","Hello World");
$attribute2Array = array("","Hello World");
$attribute3Array = array("","Hello-World");
switch ((string)$attribute) {
case "$attribute2Array[1]":
$attributeArray[1] = "selected";
break;
}
echo "
<br>Attribute:<form method=post action=attributeEdit.php>
<select name=attribute>
<option value=$attribute2Array[0] $attributeArray[0]>$attribute3Array[0]</option>
<option value=$attribute2Array[1] $attributeArray[1]>$attribute3Array[1]</option>
</select></br>
";
Instead I just created a new array and switched against it with "-" instead of spaces show the space form on the webpage. The dashed values were saved in MySQL.