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

Link to comment
Share on other sites

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";
?>

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.