Объект $Vote, созданный из класса Graph должен при помощи метода drawGraph() строить диаграмму результатов голосования. Данные о голосовании скрипт берет в базе данных. Данные про базу данных берет из файла config.php. Вот код:
Код | <?php class Graph { //define propeties public $nameOfGraph; public $tableWidth; private $color; private $colorCount; private $host; private $user; private $pass; private $db;
// constructor public function __construct() { $this->tableWidth = 400; $this->color = array('#99FFFF', '#99FFCC', '#FF99FF', '#FF9900', '#FFFF99'); $this->colorCount = 0; } // define methods public function getConfigOfDB($configFile) { include($configFile); $this->host = $host; $this->user = $user; $this->pass = $pass; $this->db = $db; } public function connectDB() { $connection = mysql_connect($this->host, $this->user, $this->pass) or die('ERROR: Unable to connect!'); // select database mysql_select_db($this->db) or die('ERROR: Unable to select database!'); } private function drawNameOfGraph() { echo '<h2>'.$this->nameOfGraph.'</h2>'; } public function getAnswerSum() { // make query of answer counts with this qid $a1query = "SELECT aid, acount FROM answers WHERE qid = '$qid'"; $a1result = mysql_query($aquery) or die("ERROR: $query.".mysql_error()); $row1 = mysql_fetch_array($a1result); foreach ($row['acount'] as $a1count) { $answerSum += $a1count; } } public function getAnswerWidth() { $atitleWidth = round($tableWidth/3); $graphWidth = round($row->acount*($tableWidth - $atitleWidth)/$answerSum); $graphRest = ($tableWidth - $graphWidth); $answerWidth = array($graphWidth, $graphRest, $atitleWidth); } public function drawGraph() { // connect database and select DB $this->connectDB(); // draw title echo '<table width = "'.$this->tableWidth.'"><tr><td>'; echo $this->drawNameOfGraph($this->nameOfGraph); echo '</td></tr>'; // draw graph table // draw questions and answers // make query of qtitles $query = "SELECT qid, qtitle FROM questions ORDER BY qdate"; $result = mysql_query($query) or die("ERROR: $query.".mysql_error()); // check if there are any questions if (mysql_num_rows($result) <= 0) die('ERROR: there are no questions or DB error'); // draw questions while ($row = mysql_fetch_object($result)) { $qid = $row->qid; // get sum of answers count for this qid $this->getAnswerSum(); echo '<table width = "'.$tableWidth.'">'; // draw name of question echo '<tr><td>'; echo '<t3>'.$row->qtitle.'</t3>'; echo '</td></tr>'; // make query of answers with this qid $aquery = "SELECT aid, atitle, acount FROM answers WHERE qid = '$qid'"; $aresult = mysql_query($aquery) or die("ERROR: $query.".mysql_error()); // get an array of width of answer row echo $this->getAnswerWidth(); $ans = 0; // draw list of answers with persetns while($row = mysql_fetch_object($aresult)) { // draw space line echo '<tr height = "5px"><td></td></tr>'; // draw answer row echo '<tr><td bgcolor = "'.$this->color[$colorCount].'" width = "'.$answerWidth[$ans].'"></td>'; $ans++; echo $this->getAnswerPersent(); echo '<td width = "'.$answerWidth[$ans].'"></td>'; $ans++; echo '<td width = "'.$answerWidth[$ans].'">'.$row->atitle.'</td></tr>'; $colorCount++; } echo '</table>'; } } } ?>
<html> <head> <title>Statistics</title> </head> <body>
<?php
$Vote = new Graph; $Vote->nameOfGraph = 'Статистика відповідей на питання'; $Vote->getConfigOfDB('config.php'); $Vote->drawGraph();
?> </body> </html>
|
Сейчас уперся в строки 69, 70. При запуске скрипта вываливается сообщение:
Цитата | ERROR: .Query was empty
|
В чем может быть ошибка? |