Jump to content

[SOLVED] radio buttons populated by mysql using php


littlehelp

Recommended Posts

ok i am gonna be getting some information from a database and then populating the radio buttons with the information and what i am wondering is how to make it to where if there is only 2 pieces of data retrieved from the db then i only want 2 radio buttons if there is 4 then i want 4 to display?

<html>
<head>
</head>
<body >
<form name="myform">
  <input type="radio" value="1" name="R1">Value 1<br>
  <input type="radio" value="2" name="R1">Value 2<br>
  <input type="radio" value="3" name="R1">Value 3<br>
  <input type="radio" value="4" name="R1">Value 4<p>

</form>
</body>
</html>

 

Thanks for any help in advance

like so?

 


<?php

$query="SELECT * FROM table WHERE 1";

$res=mysql_query($query);

     echo "<p>\n";

while($row=mysql_fetch_array($row)){
$value=$row['value'];
$display=$row['display'];

echo "<input type=\"radio\" name=\"R1\" value=\"$value\">$display<br />\n";

}//end while
     
echo "</p>\n";
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.