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'];
}
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'];
}
}
?>