Page 1 of 1

radio buttons

Posted: Wed Sep 02, 2009 10:45 am
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

Re: radio buttons

Posted: Wed Sep 02, 2009 10:59 am
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?

Re: radio buttons

Posted: Wed Sep 02, 2009 6:51 pm
by c0mrade
thank you m8, you've really helped .. tnx a zillio again ..