SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Mar 2001
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    my db structure looks like this

    table "questions"
    - questionID
    - questiontext
    - answer
    - class

    table "classes"
    -classID
    -class (math, bio, history)

    So I have this list with all kinds of questions and i can sort them by class.

    Now, I have a form with a list of checkboxes next to each class. The user to selects the classes and specifys the number of questions he would like to see from each class.
    ex:
    0 math [0] questions
    x bio [5] questions
    x history [2] questions

    therefore, my programstructure looks like this:


    while($i <= $nrclasses){
    $var = "classID$i";
    if(isset($$var)) {
    $result = mysql_query("SELECT * FROM questions WHERE questions.classID = '$i' LIMIT count");
    //---i'm stuck beneath this
    while ($temp = mysql_fetch_array($result)){}
    //
    }
    $i++;
    }

    So my idea is to go to each class, select a number of questions from that class, and put these in one big php-array.
    And that is where i'm stuck.

    how can I go through each class, and transfer those questions in one big array?

    And how can i access them after that ?

    GreetingZ, Highvolt

  2. #2
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    //---i'm stuck beneath this
    while ($temp = mysql_fetch_array($result)){}

    If you will humour me, I would prefer use the variable name $row where you have used $temp.
    $row will be an associative array. It will contain the elements $temp["questionID"], $row["questionText"], $row["answer"] and $row["class"]

    Now the easiest thing to do is th create an array say $questions. Each element of the array $question will hold a "row" (a copy of the array $row). This will create a two dimensional array (which you can also think of as a table).
    PHP Code:
    while ($row mysql_fetch_array($result)) {
       
    // add row as a new element in the array $questions
       
    $questions[] = $row;

    In fact, it appears that this could be simplified further to :
    PHP Code:
    while ($questions[] = mysql_fetch_array($result)) {}



Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •