I want to use a php variable name instead of a literal in name field of radio button

I want to use a php variable name in the name field of a radio button instead of a literal. I can’t seem to fine an example of this. I have upload a file with my example
radioex.txt (155 Bytes)

Thank You

The second example should work ok, I use it all the time. Start with a single quote, followed by text and remember to end with double quote the single quote before adding the string. The single quote, double quote to close the string.

when I am trying a simpler example. I am getting a Undefined variable: overtime in 7
What I am trying to do is group radio buttons per line and allow radio buttons to be clicked on each line (only one radio button can be clicked per line)

tradio.php (409 Bytes)

Figured out how to do it in my practice example Will upload file With work it can be improved on

Thank You

tradio.php (404 Bytes)

Here’s my version:

<?php
declare(strict_types=1);
error_reporting(-1);
ini_set('display_errors', 'true');

$title = 'Just testing';

echo $hdr = <<< ____TMP
<!DOCTYPE HTML>
<html lang="en"> 
<head>
<title> $title </title>
</head>
<body>
<div>
____TMP;

if(0):
	$overtime = 0;
	for ($x = 0; $x <= 2; $x++) {
?>
	  <fieldset id="<?php echo $overtime; ?>"> 
	      <?php print '<input type="radio" name="' .$overtime .'" value="o"/>';?>
	      <?php print '<input type="radio" name="' .$overtime .'" value="a"/>';?>
	      <?php print '<input type="radio" name="' .$overtime .'" value="d"/>';?>
	  </fieldset>
<?php $overtime++; }

else:
	# $overtime = 0;
	for ($x = 0; $x <= 2; $x++)
	{
	  echo '<fieldset id="' . $x .'">';
	  	echo '<input type="radio" name="' .$x .'" value="o"/>';
	    echo '<input type="radio" name="' .$x .'" value="a"/>';
	    echo '<input type="radio" name="' .$x .'" value="d"/>';
	  echo '</fieldset>';
		// $overtime++;
	}
endif;	
echo '</div></body></html>';

And another using PHP HereDoc

	for ($x = 0; $x <= 2; $x++)
	{
	  echo $tmp = <<< ____TMP
	  
		  <fieldset id="$x">
		  	<input type="radio" name="$x" value="o"/>
		    <input type="radio" name="$x" value="a"/>
		    <input type="radio" name="$x" value="d"/>
		  </fieldset>

____TMP;
	}

Source

<!DOCTYPE HTML>
<html lang="en"> 
<head>
<title> Just testing </title>
</head>
<body>
<div>	  
	  <fieldset id="0">
	  	<input type="radio" name="0" value="o"/>
	    <input type="radio" name="0" value="a"/>
	    <input type="radio" name="0" value="d"/>
	  </fieldset>
	  
	  <fieldset id="1">
	  	<input type="radio" name="1" value="o"/>
	    <input type="radio" name="1" value="a"/>
	    <input type="radio" name="1" value="d"/>
	  </fieldset>
	  
	  <fieldset id="2">
	  	<input type="radio" name="2" value="o"/>
	    <input type="radio" name="2" value="a"/>
	    <input type="radio" name="2" value="d"/>
	  </fieldset>

</div></body></html>

Just trying to center the blue check box on the heading of “Delete” I don’t seem to be able to move it over to the right. Am uploading the code and output
lineup2.php (4.8 KB)
lineup2.html (6.5 KB)

Thank You

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.