This code Works perfectly I mean it show all the contents as required but I can make selection of radio button only for 1st question. If I try to select 2nd option from 2nd question even then 2nd option of 1st question is changed. I cannot make changes to any other question except 1st one
Yes, you need to make sure the id is unique as SamA74 said, by adding the $i on the end. Same for the labels - if you present three selections each with the id “4th-choice”, which one would you assign the label to? But CSS rules say the ID field must be unique on a page.
I’m surprised it makes any difference to whether you can select the values though. Maybe the quotes make the difference there.
Also read around here for reasons to stop using the old-style mysql_() functions as they’re no longer a part of the language.
So rather than writing these many questions I have used a while loop to iterate over all questions.
So obviously for 1st question radio button names must be true. For 2nd loop or iteration name should be same.
Yes, but every time you run around the loop, you present four items which all have the same id as the previous loop - so every first option has the id “1st-choice”, every second one is “2nd-choice” and so on. Not the “name”, the “id” and also the “label for”. You still have the “name” field the same for each group of four - otherwise as you say, the radio part won’t work - but you can’t put multiple IDs the same.
Do you mean that the HTML page doesn’t react correctly - i.e. when you click option two on the second question it moves the selection in option one - or do you mean when you take the data into PHP and try to process it?
when you click option two on the second question it moves the selection in option one,
No matter whatever question we select changes are made only to 1st question
My trick might be helpful to any one who needs it later
id=<?php echo ($i*100+1); ?>
id=<?php echo ($i*100+2); ?>
id=<?php echo ($i*100+3); ?>
id=<?php echo ($i*100+4); ?>
Unless you really really need the IDs (for jQuery or whatever), you’ve overcomplicated this, as you don’t need an id for label to work. You simply wrap your input and label text with the label tag.