Jump to content


Photo

why is my code adding extra charicters


Best Answer Q695, 03 May 2013 - 08:34 PM

for some reason I had to reenter the page.

Go to the full post


  • Please log in to reply
4 replies to this topic

#1 Q695

Q695

    Advanced Member

  • Members
  • PipPipPip
  • 656 posts
  • LocationMN

Posted 03 May 2013 - 07:38 PM

I know the PHP is correct, but the HTML is adding extra information, and it's not pulling up the selected information based on the statement set.

<select name="slot" size="1">
        			<option value="" <?php
                    if ($item_slot=="0"){ echo "selected";}
					?>>Pick One</option>
					<option value="1"<?php
                    if ($item_slot=="1"){ echo "selected";}
					?>>Amulet</option>
                    <option value="2"<?php
                    if ($item_slot=="2"){ echo "selected";}
					?>>Head Gear</option>
                    <option value="3"<?php
                    if ($item_slot=="3"){ echo "selected";}
					?>>Epaulets</option>
                    <option value="4"<?php
                    if ($item_slot=="4"){ echo "selected";}
					?>>Shield</option>
                    <option value="5"<?php
                    if ($item_slot=="5"){ echo "selected";}
					?>>Chest Gear</option>
                    <option value="6"<?php
                    if ($item_slot=="6"){ echo "selected";}
					?>>Weapon</option>
                    <option value="7"<?php
                    if ($item_slot=="7"){ echo "selected";}
					?>>Ring</option>
                    <option value="8"<?php
                    if ($item_slot=="8"){ echo "selected";}
					?>>Boots</option>
                    <option value="9"<?php
                    if ($item_slot=="9"){ echo "selected";}
					?>>Gloves</option>
                    <option value="10"<?php
                    if ($item_slot=="10"){ echo "selected";}
					?> >Backpack</option>
				</select>


output code

<select size="1" name="slot">
<option value="">Pick One</option>
<option value="1">Amulet</option>
<option selected="" value="2">Head Gear</option>
<option value="3">Epaulets</option>
<option value="4">Shield</option>
<option value="5">Chest Gear</option>
<option value="6">Weapon</option>
<option value="7">Ring</option>
<option value="8">Boots</option>
<option value="9">Gloves</option>
<option value="10">Backpack</option>
</select>

Edited by Q695, 03 May 2013 - 07:46 PM.

if ($problem==mark_solved){

solution ($problem);}

 

if ($skill_level==learning && $my_knowledge==the_required_level_of_knowledge){

     echo "I will try to help, because you're still $skill_level , and my skill level is at $my_knowledge";

} else {

     echo "I can't help you, go away.";

}


#2 requinix

requinix

    Playful Member

  • Moderators
  • 5,744 posts
  • LocationWA

Posted 03 May 2013 - 08:24 PM

That output looks right to me... You know you're looking at it after it's been parsed and reassembled by the browser, right? If you want to see the actual output of the code you have to do a View Source.

#3 Q695

Q695

    Advanced Member

  • Members
  • PipPipPip
  • 656 posts
  • LocationMN

Posted 03 May 2013 - 08:34 PM   Best Answer

for some reason I had to reenter the page.


if ($problem==mark_solved){

solution ($problem);}

 

if ($skill_level==learning && $my_knowledge==the_required_level_of_knowledge){

     echo "I will try to help, because you're still $skill_level , and my skill level is at $my_knowledge";

} else {

     echo "I can't help you, go away.";

}


#4 mac_gyver

mac_gyver

    Advanced Member

  • Moderators
  • 1,879 posts

Posted 03 May 2013 - 08:53 PM

you have too much code, to write, test, reenter, change, add items to, reuse for different things...

 

by defining an array to hold your data, you can write/test generic code that you can reuse for different things simply by changing the data definition -

<?php
$options[1] = "Amulet";
$options[2] = "Head Gear";
$options[3] = "Epaulets";
$options[4] = "Shield";
$options[5] = "Chest Gear";
$options[6] = "Weapon";
$options[7] = "Ring";
$options[8] = "Boots";
$options[9] = "Gloves";
$options[10] = "Backpack";

?>
<select size="1" name="slot">
<option value="">Pick One</option>
<?php

$item_slot = 2; // test value

foreach($options as $value=>$legend){
    $selected = $item_slot == $value ? " selected='selected'": '';
    echo "<option value='$value'$selected>$legend</option>\n";
}
?>
</select>

multi-purpose programming fool and resident naysayer [We try not be negative in replies, but telling someone what they're doing wrong, while staying politically correct, isn't always going to happen.]

#5 Q695

Q695

    Advanced Member

  • Members
  • PipPipPip
  • 656 posts
  • LocationMN

Posted 04 May 2013 - 12:55 PM

I originally tried doing the select with a function, but it failed, and wrote selected where the function was placed in the document.


if ($problem==mark_solved){

solution ($problem);}

 

if ($skill_level==learning && $my_knowledge==the_required_level_of_knowledge){

     echo "I will try to help, because you're still $skill_level , and my skill level is at $my_knowledge";

} else {

     echo "I can't help you, go away.";

}





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com