Jump to content


Photo

Please Help Me! Help with an error (search_array)


  • Please log in to reply
3 replies to this topic

#1 foosooo

foosooo
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 12 August 2006 - 12:51 AM

hello all and thank you all so much ahead of time for any help.. I am using a old, unsupported testing/quiz script called phptest. My webhost  is telling me since they switched me to the new servers they are getting errors in their php logs about 2gigs a day from my scipt.. Now.. I prob had the error on the old servers but they prob didnt log or didnt notice it..

Is it normal for webhosts to have logging on in php? I would say that they would have a lot of errors from all the domains...

ok so here is the error they sent me

[11-Aug-2006 19:08:08] PHP Warning:  array_search(): Wrong datatype for
second argument in
/hsphere/local/home/jonathan/rescueexams.com/firetest/question.php on line
126
[11-Aug-2006 19:08:41] PHP Warning:  array_search(): Wrong datatype for
second argument in
/hsphere/local/home/jonathan/rescueexams.com/firetest/question.php on line
126
[11-Aug-2006 19:08:57] PHP Warning:  array_search(): Wrong datatype for
second argument in
/hsphere/local/home/jonathan/rescueexams.com/firetest/question.php on line
126

So  I opened up question.php and here is lines 125-134

       // figure out which question number we are on.
        $question_number = array_search($question_id, $test_session->questions);
        // we need to compare types using the '===' comparison operator because array_search() can return
        // 0 for the index which evaluates to false using the normal '==' comparison operator
        if ($question_number === FALSE) {
            pt_exit('Fatal Error: unable to determine question number.');
        }

        // output test title and additional notes
        echo "<div class=\"form\"><center><h2>{$test_session->info['description']}</h2></center>";

as you can see this is line 126
        $question_number = array_search($question_id, $test_session->questions);


so do you need more info to diagnos the issue?
I dont seem to be having any issues as far as testing is concerned but who know for sure..

can this line safely be removed?

Any ideas?

I am migrating towards another testing script and I am looking at moodle right now any other suggestions for a feature rich script would be great.!

THANKS SOOO MUCH



#2 crazy manzaaa

crazy manzaaa
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 12 August 2006 - 06:26 AM

Maybe it would be helpful if you also include more information about "$test_session->questions" since that seemd to be the variable that the error message is pointing too.

#3 foosooo

foosooo
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 12 August 2006 - 02:57 PM

I dont have enough experiance with php to even know where to find the info you are talking about.. is it a .php file?

#4 foosooo

foosooo
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 12 August 2006 - 03:11 PM

this is all the code from the file above called question.php with the line 126 problem

hope this helps and if anyone needs more please tell me.. it doesnt seem like anyone is helping me on this here but i hope it will turn around..

<?php
/*****************************************************************************
    $Id: question.php,v 1.2 2002/10/17 17:26:44 djresonance Exp $
    Copyright 2002 Brandon Tallent

    This file is part of phpTest.

    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License
    as published by the Free Software Foundation; either version 2
    of the License, or (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*****************************************************************************/

function draw_sidebar()
{
    global $test_session, $PHP_SELF;
    echo "<div class=\"menu\">\n";

    $count = 1;
    foreach ($test_session->questions as $question_id) {
        echo pt_make_href("$PHP_SELF?question_id=$question_id", $count++);
    }

    echo "</div>\n";
}

function draw_question($question_id)
{
    global $db, $user, $strings, $question_number, $test_session;
    // edit will hold the html to display the 'edit' icon if the user is an admin
    $edit = '';
    // pull all of the info about the question from the db into our $row object
    $result = $db->query("SELECT * FROM questions WHERE question_id = $question_id");
    $row = $db->fetch_object($result);

    // begin question
    echo "<tr>\n";
    echo " <td bgcolor=\"" . pt_table_highlight(0) . "\">\n";

    $image = 'edit_light.png';
    $style = 'even';

    // show the link to edit the question if user is an admin
    if ($user->admin) {
        $edit .= pt_make_href("edit_question.php?question_id=$question_id&amp;question_type_id=$row->question_type_id", "<img src=\"images/$image\" border=\"0\">", $strings['TEST_EDIT_QUESTION']);
    }
    // create a question object based on the question_type_id
    $question = pt_inst_qclass($row->question_type_id);
    // draw the question

    if (isset($test_session->answers[$question_number])) {
        $question->draw_test_question($question_id, $question_number + 1, $edit, $style, $test_session->answers[$question_number]);
    } else {
        $question->draw_test_question($question_id, $question_number + 1, $edit, $style);
    }

    echo "  </td>\n";
    echo "</tr>\n";
    // end question
}

    require_once('./include/h.inc.php');
    pt_register('GET', 'question_id');
    pt_register('POST', 'submit', 'questions', 'question_id', 'question_number', 'prev', 'next');
    pt_register('SESSION', 'test_session');

    $question_count = count($test_session->questions) - 1;

    if (isset($next)) {

        foreach($questions as $question_id => $answer) {
            list($test_session->answers[$question_number]) = pt_clean_vars($answer);
        }

        $next_question_id = $test_session->questions[$question_number + 1];
        pt_redirect("question.php?question_id=$next_question_id");
    }

    if (isset($prev)) {

        foreach($questions as $question_id => $answer) {
            list($test_session->answers[$question_number]) = pt_clean_vars($answer);
//            $test_session->answers[$question_number] = $answer;
        }

        $prev_question_id = $test_session->questions[$question_number - 1];
        pt_redirect("question.php?question_id=$prev_question_id");
    }


    if (isset($submit)) {

        // make sure to update the answer into our test_session var
        foreach($questions as $question_id => $answer) {
            list($test_session->answers[$question_number]) = pt_clean_vars($answer);
        }

        $count = 0;

        // now, we need to reconstruct the questions array in a format that
        // $test->grade() will understand.  This is just using a little array trickery.
        foreach ($test_session->questions as $question_id) {
            $questions[$question_id] = $test_session->answers[$count++];
        }

        // instantiate the test object so we can grade the test
        $test = new cTest($test_session->test_id);

        $test->grade($questions);
        pt_redirect("view_results.php?user_id=$user->user_id&feedback=" . urlencode($strings['TEST_SCORED']));
    } else {
        require_once('./include/header.inc.php');
        // draw_sidebar();
        // print_r($test_session);

        // figure out which question number we are on.
        $question_number = array_search($question_id, $test_session->questions);
        // we need to compare types using the '===' comparison operator because array_search() can return
        // 0 for the index which evaluates to false using the normal '==' comparison operator
        if ($question_number === FALSE) {
            pt_exit('Fatal Error: unable to determine question number.');
        }

        // output test title and additional notes
        echo "<div class=\"form\"><center><h2>{$test_session->info['description']}</h2></center>";

        if ($test_session->info['notes']) {
            echo "<hr noshade=\"noshade\" size=\"1\" />\n";
            echo $test_session->info['notes'];
        }

        echo "</div>\n";
        echo "<form method=\"post\" name=\"test\" action=\"$PHP_SELF\">\n";
        echo "<div class=\"test\">\n";
        echo "<table width=\"100%\" cellspacing=\"0\" cellpadding=\"8\">\n";

        draw_question($question_id);

        echo "</table>\n";
        echo "</div>\n";
        echo "<input type=\"hidden\" name=\"question_number\" value=\"$question_number\" />\n";
        echo "<input type=\"hidden\" name=\"question_id\" value=\"$question_id\" />\n";

        // show the previous button unless we're on the first question
        if ($question_id != $test_session->questions[0]) {
            echo "<input type=\"submit\" name=\"prev\" value=\"<< {$strings['TEST_PREVIOUS_QUESTION']}\" />\n";
        }

        // show the next button unless we're on the last question
        if ($question_id != $test_session->questions[$question_count]) {
            echo "<input type=\"submit\" name=\"next\" value=\"{$strings['TEST_NEXT_QUESTION']} >>\" />\n";
        }

        echo "<input type=\"submit\"  name=\"submit\" value=\"{$strings['TEST_SUBMIT']}\" />\n";
        echo "</form>\n";

        require_once('./include/footer.inc.php');
    }
?>





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users