Jump to content

problem with radio button


mrjameer

Recommended Posts

hi,

i have a table.it's structure is like this
itemno--itemname--price
1--abc--200
2--djh--300
3--eee-400

i want to dynamically create 3 radio buttons for prices and to display these records on web page and when a user click radio button of any one the selected values should be stored in some other table.how to do this.i know how to display and store in db.problem is with dynamically creating radio buttons.please any of your help is appreciated.

thanks
mrjameer
Link to comment
https://forums.phpfreaks.com/topic/31256-problem-with-radio-button/
Share on other sites

[code]
// example retrieval of all info in your db

$sql = "select * from table";
$result = mysql_query($sql) or die(mysql_error());

while ($list = mysql_fetch_array($result)) {
  // make a radio button with the item name next to it. radio button will
  // pass all of the info associated with the item as an array called [itemname]
  echo "<input type='radio' name='{$list['itemno']}' value='{$list}'>{$list['itemname']}<br/>";
}
[/code]
[code]
<?php
//Connect to DB here
$sql = mysql_query(\"SELECT * FROM `tablename`\");
?>
<form method=\"PAGE HERE\" action=\"\">
<?php
while($row = mysql_fetch_assoc($sql)){
echo\"<input type=\'radio\' value=\".$row[\'price\'].\" name=\'\".$row[\'itemno\'].\"\'>\".$row[\'itemname\'];
}
?>
</form>
<?php
//Of course, you will need to change some of the information, but that is the basic structure.
?>
[/code]

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.