2 Replies - 387 Views - Last Post: 26 February 2013 - 12:30 PM Rate Topic: -----

#1 seth_graham  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 26-February 13

Foreach Looping through Radio Groups in PHP

Posted 26 February 2013 - 09:34 AM

Hello, I am making a quiz using PHP (no HTML form, only coded in PHP print statements) and I can't seem to figure out how to foreach loop through the choices (radio buttons) in the quiz.

Here's what I've tried:

foreach($question as $key => $value) {
		print "$key. $value<br><br>";
			foreach($choice as $key => $value) {
				print "<label><input type='radio' name='choices'>$value <--THE ISSUE IS HERE I BELIEVE</label><br />";


Thanks

This post has been edited by JackOfAllTrades: 26 February 2013 - 10:12 AM
Reason for edit:: Added code tags


Is This A Good Question/Topic? 0
  • +

Replies To: Foreach Looping through Radio Groups in PHP

#2 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3721
  • View blog
  • Posts: 12,953
  • Joined: 12-December 12

Re: Foreach Looping through Radio Groups in PHP

Posted 26 February 2013 - 10:52 AM

You are already using $key and $value in the outer-loop, give them different names in the inner-loop.

The value also needs to be repeated inside the input tag; e.g.

<input type="radio" name="sex" value="male">male<br>


BTW You are using HTML, and you need to understand HTML before you can create it with PHP.
Was This Post Helpful? 2
  • +
  • -

#3 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3730
  • View blog
  • Posts: 6,017
  • Joined: 08-June 10

Re: Foreach Looping through Radio Groups in PHP

Posted 26 February 2013 - 12:30 PM

Where does the $choices variable in the inner loop come from? Was that perhaps meant to be based on the value of the outer loop?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1