Populating radio buttons from an SQL query result set

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
varun_146100
Forum Newbie
Posts: 3
Joined: Wed Oct 22, 2008 3:48 am

Populating radio buttons from an SQL query result set

Post by varun_146100 »

Hi,
Am very new to PHP and am stuck up right now.
I have an SQL query that returns me a result set having 2 columns (Start Date , End Date)
1=> This result set needs to be generated on the selection of an item(Id) from the options in a select box.
2=> I need this result set to be displayed in radio buttons.
The user can then select one of the radio button options.He can then submit the data.

I need to know how can I achieve 1 & 2.
Please help me on this one.Will really appreciate that.
php_chik
Forum Newbie
Posts: 3
Joined: Tue Dec 16, 2008 6:42 am

Re: Populating radio buttons from an SQL query result set

Post by php_chik »

varun_146100 wrote:Hi,
Am very new to PHP and am stuck up right now.
I have an SQL query that returns me a result set having 2 columns (Start Date , End Date)
1=> This result set needs to be generated on the selection of an item(Id) from the options in a select box.
2=> I need this result set to be displayed in radio buttons.
The user can then select one of the radio button options.He can then submit the data.

I need to know how can I achieve 1 & 2.
Please help me on this one.Will really appreciate that.

I am not really sure what you mean...but it sounds like you need this..

Code: Select all

 
//set the name of your button...if you make radio buttons with the same name it gives you an option between the two
$name = 1;
 
$results = mysql_query( "SELECT * FROM details WHERE `set` = '".$set."'" );
        while( $row = mysql_fetch_array( $results ) )
        {
$result = mysql_query( "SELECT * FROM details WHERE `id` = '".$row[id]."'" );
        while( $rows = mysql_fetch_array( $result ) )
        {
echo "<input type='radio' name='$name'>$rows[name]";
                       }
//after you get a group of buttons, change the name of the next group of buttons you get by adding a number to it.
$name++;
}
 
It sounds like thats what you are looking for....
Post Reply