0

I've created a php function then used a loop to recreate the radio buttons, but now what im struggling with is the function only has one name, but it loops for several different topics. How do i differentiate each answer from one another..? (if that made any sense)

For example; the first two questions, faculty then the basic info i haven't bothered with php due to it not being repetitive enough..

With these i understand that each answer will be paired up with their names, such as faculty, moduleCode etc.

With the php function it looks like this;

        }
    echo '<br/><br/>';
        }
    }
?>

Then just inserting;

  <?php
    ratingLoop(4, 6);
?>

where it is needed.

But how would i now separate the question selections as in the function ive only given it the name radioGroup, basically im confusing myself but simply want to know.. How would i take each radio selection from the loop and input it into mySQL if they dont have unique names?

Thank you in advance for any tips!

1 Answer 1

1

Consider having another identifier string to pass into the function.

function ratingLoop($identifier, $group, $answer){
        for($i = 1; $i <= $group; $i++){
        for($a = 1; $a <= $answer; $a++){
            echo '<input type="radio" name="radioGroup_'.$identifier.'_'.$i." value="'.$a.'">'.$a;
        }
    echo '<br/><br/>';
        }
    }

Invoke it like so:

   ratingLoop('satisfication', 3, 3);
   ratingLoop('quality_of_service', 3, 3);
Sign up to request clarification or add additional context in comments.

2 Comments

How would i give each radio button a name by just adding $group to the function?
Sorry, quite new to php - i still dont understand the concept.. what would i do with the $i and $a?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.