Avatar billede luke2009 Nybegynder
13. marts 2009 - 11:10 Der er 3 kommentarer og
1 løsning

php web applikation virker ikke mere

Efter at have opgraderet til php5 virker min webapplikation ikke længere. Jeg får en fejlmedelelse om , at den ikke forstår $this, og det er brugt mange gange i scriptene.
$this refereer vel til noget udenfor funktionen/metoden, men hvad skal $this ændres til for at scriptene igen virker?

eks:

function _getQuizConfigs( )
    {
        $this->db->doQuery( "SELECT per_page, shuffle_choices, shuffle_questions FROM nq_Quizzes WHERE id=" . $this->quiz );
        $temp = $this->db->nextAssoc();
        $this->qPerPage = $temp['per_page'];
        $this->shuffleC = $temp['shuffle_choices'];
        $this->shuffleQ = $temp['shuffle_questions'];
    }
Avatar billede showsource Seniormester
13. marts 2009 - 11:18 #1
ehh, synes det ser lidt underligt ud, men måske

global $this;

inde i din funktion som det første.
Avatar billede dkfire Nybegynder
13. marts 2009 - 12:59 #2
Den funktion som du viser er en del af en klasse. Du bliver nød til at vise hele din klasse og hvordan du kalder den funktion du viser her.
Avatar billede luke2009 Nybegynder
13. marts 2009 - 16:01 #3
Jamen, her er så hele klassen. Den er lang, derfor tog jeg bare een funktion som eksempel. Eksemplet kaldes fra den første funktion i klassen.

<?php

/*
* Coding formatted for standard 4-space tabs.
*/
require_once( "Database.class.php" );
require_once( "Question.class.php" );
require_once( "Page.display.php" );
require_once( "config.php" );

class Page {
   
    var $quiz;
    var $pageNum;
    var $db;
    var $questions;
    var $qPerPage;
    var $shuffleQ;
    var $shuffleC;
   
    function Page( $quizID, $pageNum, $userAnswers )
    {
        $this->quiz = $quizID;
        $this->pageNum = $pageNum;
        $this->answers = $userAnswers;
        $this->questions = array( );
       
        $this->db = new Database( CFG_DB_SERVER, CFG_DB_USERNAME, CFG_DB_PASSWORD, CFG_DB_NAME );
       
        if( is_numeric( $this->quiz ) && intval( $this->quiz ) == $this->quiz && $this->quiz > 0 )
        {
            $this->_getQuizConfigs( );
            if( $this->qPerPage == 0 )
            {
                $this->db->doQuery( "SELECT COUNT(*) AS count FROM nq_Questions WHERE quiz=" . $this->quiz );
                $resRow = $this->db->nextAssoc( );
                $this->qPerPage = $resRow['count'];
            }
            $this->_fetchQuestions( );
        }
    }
   
    function display( )
    {
        $this->_generatePage( );
    }
   
    function _fetchQuestions( )
    {
        $query = "SELECT id,q.question AS q, reason " .
                "FROM nq_Questions q, nq_Choices c " .
                "WHERE id=c.question AND quiz=" . $this->quiz . " " .
                "GROUP BY id,q.question,reason HAVING COUNT(c.position) > 1";
               
        if( $this->shuffleQ )
        {
            $numSessionID = preg_replace( "[\D]", "", session_id() );
            $randSeed = substr( $numSessionID, strlen($numSessionID)-6, 3 );
            $randSeed = $randSeed + ( substr( "$this->quiz", strlen( $this->quiz ) - 1 ) * 300 );
            $query = $query . " ORDER BY RAND(" . $randSeed * 10000000 . ")";
        }
        $this->db->doQuery( $query );
    }
   
    function _makeIntroPage( )
    {
        $query = "SELECT name,intro FROM nq_Quizzes WHERE id=" . $this->quiz . " LIMIT 1";
        $this->db->doQuery( $query );
       
        if( !( $quizInfo = $this->db->nextAssoc( ) ) )
        {
            $errText = "The quiz you are trying to access (ID " . $this->quiz . ") doesn't exist!<br><br>" .
                      "<a href=\"" . CFG_QUIZ_URL . "\">Choose a Valid Quiz</a><br>";
            new Error( "NQ-INT-001",$errText, ERR_LEVEL_MINOR, true );
        }
       
        showIntro( $quizInfo['name'], $quizInfo['intro'] );
    }
   
    function _makeSelectionPage( )
    {
        // Uncomment following to show ALL quizzes on selection page
        // (Not just ones that have valid questions)
        //$query = "SELECT id,name FROM Quizzes ORDER BY id ASC";
        $query = "CREATE TEMPORARY TABLE Temp
                  SELECT id AS qid,quiz
                  FROM nq_Questions q, nq_Choices c
                  WHERE id=c.question
                  GROUP BY id,quiz HAVING COUNT(c.position) > 1";
        $this->db->doQuery( $query );
       
        $query = "SELECT id,name
                  FROM nq_Quizzes,Temp
                  WHERE id=quiz
                  GROUP BY id,name";
        $this->db->doQuery( $query );
           
        $quizNames = array( );
        while( $quizName = $this->db->nextAssoc( ) )
            $quizNames[$quizName['id']] = $quizName['name'];
       
        showSelectionPage( $quizNames );
    }
   
    function _generatePage( )
    {
        if( !is_numeric( $this->quiz ) || intval( $this->quiz ) != $this->quiz )
            $this->_makeSelectionPage( );
       
        if( !$this->pageNum && $this->pageNum !== 0 )
        {
            $this->_makeIntroPage( );
            return;
        }
        if( $this->db->resultIsEmpty( ) )
        {
            $errText = "This quiz has no complete questions for you to answer.<br><br>" .
                      "<a href=\"" . CFG_QUIZ_URL . "\">Choose Another Quiz</a><br>";
            new Error( "NQ-GPG-001", $errText, ERR_LEVEL_MINOR, true );
        }
       
        $firstQ = $this->qPerPage * $this->pageNum;        // Calculate position of the first question on this page
       
        // Try to jump to first question of quiz
        // If fails, try to make results
        if( !$this->db->resultJump( $firstQ ) )    // Go to first question on this page:
        {
            while( $temp = $this->db->nextAssoc( ) )
                $this->questions[ $temp['id'] ] = new Question( $temp['id'], $temp['q'], $temp['reason'], $this->shuffleC );
            printResPage( $this->questions );
            //$this->_showResults( );
        }
        else
        {
            for( $i=0; ( $i < $this->qPerPage ) && ( $temp = $this->db->nextAssoc( ) ); $i++ )
                $this->questions[ $temp['id'] ] = new Question( $temp['id'], $temp['q'], $temp['reason'], $this->shuffleC );
            $totalPages = ceil( $this->db->resultNumRows() / $this->qPerPage );
            printQPage( $this->questions, $firstQ+1, $this->pageNum, $totalPages );
        }
    }
   
    function _getQuizConfigs( )
    {
        $this->db->doQuery( "SELECT per_page, shuffle_choices, shuffle_questions FROM nq_Quizzes WHERE id=" . $this->quiz );
        $temp = $this->db->nextAssoc();
        $this->qPerPage = $temp['per_page'];
        $this->shuffleC = $temp['shuffle_choices'];
        $this->shuffleQ = $temp['shuffle_questions'];
    }
}

?>
Avatar billede luke2009 Nybegynder
16. maj 2009 - 09:45 #4
Jeg rydder lige op.
Jeg fandt ikke ud af at løse problemet kodemæssigt. Fandt et webhotel, der understøtter php4.
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Vi tilbyder markedets bedste kurser inden for webudvikling

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester