gabenut Posted April 17, 2006 Share Posted April 17, 2006 Hello,I have been doing some work on making a survey with PHP and MySQL. I am having a problem displaying the image for the graph. I have been using the imagecreate() function in PHP.The error displayed is: [b]The image "survey.php" cannot be displayed, because it contains errors.[/b]Here's the coding: [code]<?phpsession_start();Header("Content-Type: image/gif");$query = "SELECT count(question_id) FROM final WHERE QuestionID=1";$result = mysqli_query ($dbc, $query);$row = mysqli_fetch_row($result);$nTotalVotes=$row[0];$query = "SELECT final.answer_id, answers.answer as tx, count (final.answer_id) as ct FROM final, answers WHERE final.answer_id = answer.answer_id AND final.question_id =1 GROUP BY final.answer_id";$result = mysqli_query ($dbc, $query);$xDim = 400;$yDim = 15+(mysqli_num_rows($result)*15);$im = ImageCreate($xDim, $yDim);$backg = ImageColorAllocate($im, 255,255,200);$blue = ImageColorAllocate($im, 0, 0, 255);$nY = 0;while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)){ $percVote = round(($row['ct']/$nTotalVotes)*100,2); $percWidth = ($percVote * $xDim / 100) - 10; ImageFilledRectangle($im, 0, $nY+1, $percWidth, $nY+10, $blue); ImageString($im,2,$percWidth + 5, $nY+1, $row['tx'] . " " . $percVote . "%", $blue); $nY=$nY+15;}ImageGIF($im);?>[/code]Any help would be greatly appeciated, thank you! Quote Link to comment Share on other sites More sharing options...
Barand Posted April 17, 2006 Share Posted April 17, 2006 Comment out the header line and run script[code]// Header("Content-Type: image/gif");[/code]Errors should then be reported.And you need [code]imagedestroy($im);[/code]at end Quote Link to comment Share on other sites More sharing options...
gabenut Posted April 17, 2006 Author Share Posted April 17, 2006 Thanks very much for your help. The errors I got were these:Warning: mysqli_fetch_row() expects exactly 1 parameter, 2 given in survey.php on line 10Warning: mysqli_num_rows() expects exactly 1 parameter, 2 given in survey.php on line 17Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in survey.php on line 22GIF87a?I'm not sure what these mean, so again, any help would be much appreciated. Thank you! Quote Link to comment Share on other sites More sharing options...
Barand Posted April 17, 2006 Share Posted April 17, 2006 Check queries working correctly and use something like[code]$result = mysqli_query ($dbc, $query) or die(mysqli_error());[/code](I hope that's right, my v4 manual hasn't got msqli) Quote Link to comment Share on other sites More sharing options...
gabenut Posted April 17, 2006 Author Share Posted April 17, 2006 Thank you very much! The errors have disappeared but now this is displayed:GIF87a?I took the comments away from the header, just to check, and the original error comes up. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.