Jump to content

While loop inside while loop


madmenyo

Recommended Posts

Hey,

 

for each loop $slotcounter returns me "4" .... wich is weird because i do get 4 buttons displayed.

 

print $_POST['wslot']; return only slot4 to mo wichever button i click. I need it to be button 1,2,3,4

 

<?php
if (isset($_POST['useweapon']))
{
print $_POST['useweapon'];
echo "</br>";
print $_POST['wslot'];
}
}    
?>

<form action="" method="post">
    <?php
$slotcounter = 1;
//while ($slotcount['weaponslots'] >= $slotcounter)
while ($slotcounter <= 4)
{

?>
    <input type="hidden" value="slot<?php echo $slotcounter;?>" name="wslot"> 
    <INPUT TYPE="image" SRC="images/slot<?php echo $slotcounter;?>.jpg" HEIGHT="11" WIDTH="11" BORDER=0 ALT="^" name="useweapon" value="<?php echo $weaponrows['weaponID'];?>">
    <?php
$slotcounter++;
}
?>
</form>

 

 

Link to comment
Share on other sites

It seems to be working for me.

 

 

BUUUT...

 

<?php
if (isset($_POST['useweapon']))
{
print $_POST['useweapon'];
echo "</br>";
print $_POST['wslot'];
}
}    
?>

 

Why is there a second curly brace after this? is it in another if or while loop?

Link to comment
Share on other sites

I actually had to reverse $slotcounter and $weaponrows for it to work, i don't know why but it works like it should. i speneded like 2 hours on this :D

 

The bracket is from another statement, i shouldn't have included that in the code sorry,

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.