littlehelp Posted July 6, 2009 Share Posted July 6, 2009 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 https://forums.phpfreaks.com/topic/164990-solved-radio-buttons-populated-by-mysql-using-php/ Share on other sites More sharing options...
seventheyejosh Posted July 6, 2009 Share Posted July 6, 2009 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 https://forums.phpfreaks.com/topic/164990-solved-radio-buttons-populated-by-mysql-using-php/#findComment-869980 Share on other sites More sharing options...
littlehelp Posted July 6, 2009 Author Share Posted July 6, 2009 not tried yet but i think that will work. I will try it and get right back to you, Thanks alot. Link to comment https://forums.phpfreaks.com/topic/164990-solved-radio-buttons-populated-by-mysql-using-php/#findComment-869983 Share on other sites More sharing options...
littlehelp Posted July 6, 2009 Author Share Posted July 6, 2009 The only problem is it allows me to select more than one radio button lol Link to comment https://forums.phpfreaks.com/topic/164990-solved-radio-buttons-populated-by-mysql-using-php/#findComment-870006 Share on other sites More sharing options...
littlehelp Posted July 6, 2009 Author Share Posted July 6, 2009 Ignore that i accidentally changed the name somehow Link to comment https://forums.phpfreaks.com/topic/164990-solved-radio-buttons-populated-by-mysql-using-php/#findComment-870008 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.