0
<!doctype html>
<html>
<head>
<title>Untitled Document</title>
</head>
<body>
<?php
 $x = 5;
while($x>0)
  {
  echo 'Line' . $x;
  echo "<br>";
  $x--
  }

?>
</body>
</html>

Now, along with the output i want to create 5 submit buttons. one button will be created in each iteration of the loop above. is it possible?

2
  • 3
    Why not just give it a shot? Commented Apr 15, 2014 at 2:03
  • 3
    Just echo out the button html code? Commented Apr 15, 2014 at 2:03

2 Answers 2

3

try to use href will be better. if you use submit button it need create 5 different form and the code will look messy.

try this:

<?php
 $x = 5;
while($x>0)
  {
  echo 'Line' . $x;
  echo "<a href='test.php?a=$x'>test</a>";
  echo "<br>";
  $x--
  }

?>

after that :

call the value in other page :

if($_REQUEST['a'] == '1'){
//code here
}
else if($_REQUEST['a'] == '2'){
//code here
}

......
Sign up to request clarification or add additional context in comments.

2 Comments

it is useful for you?
"if you use submit button it need create 5 different form and the code will look messy." --- Not if you place <form></form> tags outside the loop.
0

Try this, just echoing <input type=submit>.

$x = 5;
while($x>0)
{
    echo 'Line' . $x;
    echo '<input type=submit value="button '.$x.'"></input>';
    echo '<br>';
    $x--
}

2 Comments

use also 'value="button'.$x.'"'
@ParthTrivedi Actually value="button '.$x.'"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.