user3520573
user3520573

Reputation: 117

create submit buttons inside php loop

<!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?

Upvotes: 0

Views: 1685

Answers (2)

Ethan Brouwer
Ethan Brouwer

Reputation: 1005

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--
}

Upvotes: 0

user3517652
user3517652

Reputation: 94

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
}

......

Upvotes: 3

Related Questions