Dividing an array into smaller arrays

Discussion in 'PHP' started by Shaimaa, Feb 10, 2010.

  1. #1
    Dear all,
    I want to ask about who to divide an array into smaller arrays and use every one of them to do something

    the array I'm talking about contains values coming from database

    $select = "select description from Answer where question_ID=".$row['Q_ID'];
    
      $res = mysql_query($select);
    
      while ($r = mysql_fetch_array($res))
      {
    	echo '<input type="radio" name="answer" value="'.$r['description'].'" />';
    	echo $r['description'];
    	echo "<br/>";
    
      }
    PHP:
    The problem is:

    I'm doing a quiz system (multiple choice exam)

    I return Question and Answers of these questions and display them... this is done OK

    Each Question is printed right but the user can only choose only one answer for all questions

    See this link:

    http://www.mooled.com/quiz/quiz.php

    I want to solve this problem, do anyone know how to solve it?
     
    Shaimaa, Feb 10, 2010 IP
  2. Jordonias

    Jordonias Active Member

    Messages:
    331
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    58
    #2
    Make a loop to create an array of arrays.
    You need to be more specific as to the data the array is pulling from the database and how many arrays you want.

    Shoot me a pm if you need more help
     
    Jordonias, Feb 10, 2010 IP
  3. thorie

    thorie Peon

    Messages:
    35
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Give each set of radio fields a unique name. Like answer_1 answer_1 answer_1, then answer_2 answer_2 answer_2, etc.
     
    thorie, Feb 10, 2010 IP
  4. Shaimaa

    Shaimaa Peon

    Messages:
    28
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thanks all

    I tried the 2nd solution and it works well :)
     
    Shaimaa, Feb 11, 2010 IP