Page 2 of 2 FirstFirst 12
Results 11 to 14 of 14
  1. #11

    Since naka store man sa database imo question, ako solution would be like this...

    /* DECLARE ARRAY FOR PREV_QUSTIONS nga SESSION */
    if(!isset($_SESSION['rolled_pages'])){ $_SESSION['rolled_pages'] = array(); }

    /* We will use the contents in the array to cross match sa imo query. This is to avoid the same question being queried again in the next page */

    $q = mysql_query("select question_id, question from sample.qustionaire where question_id not in ('" . implode("', '", $_SESSION['rolled_pages']) . "') order by rand() limit $pageOffset, $rowsPerPage;");


    $i = 1;

    print "<table>";
    while($row = $mysql_fetch_array($q)) {
    print "<tr><td>$i</td><td>$row['question']</td></tr>";
    /* ASSUMING NGA IMO SAD GI STORE IMO CHOICES UG DBASE W/ REFERENCE SA QUESTION ID */
    $q2 = mysql_query("select choice_id, choices from sample.choices where question_id='$row[question_id]' order by rand();");
    /* Kani, aside sa imo gi randomize imo questions, gi-randomize pa jud imong choices */
    while($inner_row = mysql_fetch_array($q2)) {
    print "<tr><td><input type=radio name='radio'></td><td>$inner_row['choices']></td></tr>";
    }
    $i++;
    /* Insert the question_ids to the array, every loop */
    array_push($_SESSION['rolled_pages'],$row['question_id']);
    /* on the next page, i-implode nato ang content sa array, then simply query contents in your questionaire database that is not on the $_SESSION['rolled_pages'] (in which we declare it as an array)*/
    }
    print "</table>";

    Now, you can use the same method to display previous pages, store the question_ids per page into a session, then "implode" it, crossmatch it to the your questionaire table...

    Your next challenge is to tagged what is selected by the user (answer niya)... Sa ako part, I'd go for AJAX, onclick event sa radio, istore na niya sa user answer database...

  2. #12
    Im not sure if this will work ...

    You can try adding a randomized number in your query, sorting the records by that number and only acquiring the number of records needed.

    This is if you want the random record picking done at the database server.

    eg.

    select top 10 *, rnd(?) as rn from table order asc rn

  3. #13
    Quote Originally Posted by istp1980 View Post
    Im not sure if this will work ...

    You can try adding a randomized number in your query, sorting the records by that number and only acquiring the number of records needed.

    This is if you want the random record picking done at the database server.

    eg.

    select top 10 *, rnd(?) as rn from table order asc rn
    that would cause some minor problems.
    What if the ID's in the table are not in proper sequence? (deleted questions)

    The solution to that is to use the LIMIT at the end of the query. Creating a dummy column to regenerate numbers in random (or regenate dummy numbers), then sort them in order.

    Another and easiest way is to use ORDER BY RAND() and also using LIMIT at the end.
    You can read this ... http://www.akinas.net/pages/en/blog/mysql_random_row/
    Last edited by dodie; 03-24-2010 at 08:06 AM.

  4. #14
    Quote Originally Posted by dodie View Post
    Another and easiest way is to use ORDER BY RAND() and also using LIMIT at the end.
    You can read this ... Selecting random record from MySQL database table. ~ Blog ~ Akinas
    Exactly... the easiest way as what I have described in my sample..

    The only challenge with this is when the user click the previous pages... Because you have to definitely display the exact order of questions on the previous pages...

    My approach would be again, put question_ids in into a session which is declared as array. create session values per page so that we could used those values unyag query nato kon moclick ang user ug previous page....

  5.    Advertisement

Page 2 of 2 FirstFirst 12

Similar Threads

 
  1. yp4sc? online exam?
    By cobarde in forum Campus Talk
    Replies: 2
    Last Post: 09-11-2014, 07:34 AM
  2. php job exam
    By theKidFrankie in forum Career Center
    Replies: 0
    Last Post: 02-19-2011, 09:07 PM
  3. Want To Buy: Luna online gold for php
    By gOdz in forum Everything Else...
    Replies: 0
    Last Post: 11-01-2009, 11:17 PM
  4. PHP certification exam
    By roxangui in forum Websites & Multimedia
    Replies: 0
    Last Post: 08-19-2009, 02:28 PM
  5. how to launch web page [php] online?
    By hybrid_X in forum Websites & Multimedia
    Replies: 0
    Last Post: 04-14-2006, 05:36 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
about us
We are the first Cebu Online Media.

iSTORYA.NET is Cebu's Biggest, Southern Philippines' Most Active, and the Philippines' Strongest Online Community!
follow us
#top