radio buttons

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
c0mrade
Forum Newbie
Posts: 19
Joined: Mon Oct 06, 2008 4:17 am

radio buttons

Post by c0mrade »

Hi all,

I'm working on a website who sells books, and I need some help here is the thing.. I have table of 2 rows and 7 columns in each row, in each column there is radio button with a certain value inside .. now I need to make next preview page where I show which price has been selected in the two rows. The number of rows with radio-buttons isn’t fixed, so I need to make sure that my code can handle this. Does anyone have suggestion for me, get me going towards right direction would be great as well.

Thank you
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Re: radio buttons

Post by Skara »

I'm not entirely sure I understand exactly what you're going for, but maybe this is what you need...

Code: Select all

<input type="radio" name="rad[0]" value="a" />
<input type="radio" name="rad[0]" value="b" />
<input type="radio" name="rad[0]" value="c" />
<input type="radio" name="rad[1]" value="a" />
<input type="radio" name="rad[1]" value="b" />
<input type="radio" name="rad[1]" value="c" />
<input type="radio" name="rad[2]" value="a" />
<input type="radio" name="rad[2]" value="b" />
...etc
So.. depending on your row/column structure...

Code: Select all

for ($i=0; $i < $columns; $i++) {
    for ($n=0; $n < $rows; $n++) {
        echo '<input type="radio" name="rad[', $i, '][', $n, ']" value="a" />',
             '<input type="radio" name="rad[', $i, '][', $n, ']" value="b" />',
             '<input type="radio" name="rad[', $i, '][', $n, ']" value="c" />';
    }
}

Code: Select all

foreach ($_POST['rad']) {
    foreach ($_POST['rad'][column]) {
    }
}
Something like that. Does that help any?
c0mrade
Forum Newbie
Posts: 19
Joined: Mon Oct 06, 2008 4:17 am

Re: radio buttons

Post by c0mrade »

thank you m8, you've really helped .. tnx a zillio again ..
Post Reply