Jump to content


Photo

Image manipulation error


  • Please log in to reply
4 replies to this topic

#1 gabenut

gabenut
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 17 April 2006 - 03:15 PM

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: The image "survey.php" cannot be displayed, because it contains errors.

Here's the coding:

<?php
session_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);


?>

Any help would be greatly appeciated, thank you!



#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 17 April 2006 - 06:07 PM

Comment out the header line and run script

// Header("Content-Type: image/gif");

Errors should then be reported.

And you need

imagedestroy($im);

at end

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 gabenut

gabenut
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 17 April 2006 - 06:18 PM

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 10

Warning: mysqli_num_rows() expects exactly 1 parameter, 2 given in survey.php on line 17

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in survey.php on line 22
GIF87a?

I'm not sure what these mean, so again, any help would be much appreciated. Thank you!

#4 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 17 April 2006 - 06:26 PM

Check queries working correctly and use something like

$result = mysqli_query ($dbc, $query) or die(mysqli_error());

(I hope that's right, my v4 manual hasn't got msqli)
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#5 gabenut

gabenut
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 17 April 2006 - 06:40 PM

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users