Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2004
    Posts
    84

    Unanswered: Query result does not survive submit!

    If there is a line:

    $result = mysql_query("SELECT * FROM table ORDER BY RAND();

    in the middle of the script, and at the bottom there is submit button, $result has to be renewed, during complete page refresh.

    I tried to put something like:
    if ($submitted != 1){
    $result = mysql_query("SELECT * FROM table ORDER BY RAND();
    }

    Of course, I control the content of the $submitted variable, but it does not have it anymore in the memory. It says:

    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in c:\inetpub\wwwroot\script.php on line 112

    I have to answer why I do need the same $result ORDER - Its because of the test-exam script, after questions, answers are submitted, the same page has to have the same order of questions. Means - if I renew the query, order would be absolutely different.

    Is there any possibility for the $result to be remembered? I tried to put

    global $result;

    at the beginning of the script it does not help.

    Any idea?

  2. #2
    Join Date
    Jan 2004
    Location
    India
    Posts
    168
    if ($submitted != 1){
    $result = mysql_query("SELECT * FROM table ORDER BY RAND();
    }
    This script should be like this
    if ($submitted != 1){
    $result = mysql_query("SELECT * FROM table ORDER BY RAND()");
    }
    You where missing a quots and a closig parentesis.

    If this is not the issues please post back the complet code of your page or alteast the post of the code where this query is written.

    Regards
    Rajesh
    Freelance and Technology Consultant
    -------------------
    Dreams are for ever
    -------------------

  3. #3
    Join Date
    Apr 2005
    Location
    Baltimore, MD
    Posts
    297
    When you get your result set, fetch the results in to an array and use session variables to store that array.

    http://us2.php.net/manual/en/ref.session.php
    http://us2.php.net/manual/en/reserved.variables.php

  4. #4
    Join Date
    Mar 2004
    Posts
    84
    Thanks for posts!

    rajesh_r_r, I just put the line for info, sorry cause the line was not finished well.

    jfulton, what you mentioned, that's what I am doing now. Just I am trying not to get * all fields, but just ID in the array, and I would put it into the session variable.

    After submitting the form, the page reload, and the while loop will go thru the area, and will fetch all records, sorted as they were sorted originally.

    I am working on optimization of everything....

Posting Permissions

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