Jump to content

Image manipulation error


gabenut

Recommended Posts

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]<?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);


?>[/code]

Any help would be greatly appeciated, thank you!

Link to comment
Share on other sites

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!
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.