<?php
date_default_timezone_set("America/New_York");
require("db_vars.php");
// Connect to the database
$dbc = mysqli_connect($db_hostname, $db_database, $db_username, $db_password);
// Custom function to draw a bar graph given a data set, maximum value, and image filename
function draw_bar_graph($width, $height, $data, $max_value, $filename) {
// Create the empty graph image
$img = imagecreatetruecolor($width, $height);
// Set a white background with black text and gray graphics
$bg_color = imagecolorallocate($img, 255, 255, 255); // white
$text_color = imagecolorallocate($img, 255, 255, 255); // white
$bar_color = imagecolorallocate($img, 0, 0, 0); // black
$border_color = imagecolorallocate($img, 192, 192, 192); // light gray
// Fill the background
imagefilledrectangle($img, 0, 0, $width, $height, $bg_color);
// Draw the bars
$bar_width = $width/((count($data) * 2) + 1);
for ($i = 0; $i < count($data); $i++) {
imagefilledrectangle($img, ($i * $bar_width * 2) + $bar_width, $height,
($i * $bar_width * 2) + ($bar_width * 2), $height - (($height/$max_value) * $data[$i][1]), $bar_color);
imagestringup($img, 5, ($i * $bar_width * 2) + ($bar_width), $height - 5, $data[$i][0], $text_color);
}
// Draw a rectangle around the whole thing
imagerectangle($img, 0, 0, $width - 1, $height - 1, $border_color);
// Draw the range up the left side of the graph
for ($i = 1; $i <= $max_value; $i++) {
imagestring($img, 5, 0, $height - ($i * ($height/$max_value)), $i, $bar_color);
}
// Write the graph image to a file
imagepng($img, $filename, 5);
imagedestroy($img);
} // End of draw_bar_graph() function
// if (mysqli_num_rows($data) != 0) {
// First grab the user's responses from the response table (JOIN to get the topic and category names)
$query = "SELECT ts.species_name, COUNT(ti.species_id) " .
"FROM tree_species ts " .
"INNER JOIN tree_individuals ti ON ts.species_id = ti.species_id " .
"GROUP BY ts.species_name'";
$data = mysqli_query($dbc, $query);
$tree_totals = array();
while ($row = mysqli_fetch_array($data)) {
array_push($tree_totals, $row);
}
// Generate and display the mismatched category bar graph image
echo '<h4>Mismatched category breakdown:</h4>';
draw_bar_graph(480, 240, $tree_totals, 5, 'treetotalgraph.png');
echo '<img src="treetotalgraph.png" alt="Tree total graph" /><br />';
//}
mysqli_close($dbc);
?>
: mysqli_query()가 매개 변수 1 mysqli 될 것으로 예상, 부울 G에 주어진 : 라인 \ 학생들 \의 test.php 54PHP 오류, 부울 논리에 다음과 같은 오류를</p> <p>경고 생성
경고 :
경고 : imagepng() [F 선 56
불일치 카테고리 분석에 \ 학생 \의 test.php : mysqli_fetch_array()는 매개 변수가 null G 1에 주어진 mysqli_result 될 것으로 예상 unity.imagepng] : 쓰기 위해 'treetotalgraph.png'을 열 수 없습니다 : 43 행의 G : \ Students \ test.php에서 권한이 거부되었습니다.
경고 : mysqli_close()는 mysqli로, : \ Students \ test.php on line 68
? 오류를 찾으셨습니까? – Charles
오류 메시지의 의미는 명확합니다. mysqli_num_rows()를 사용하려면 전달 된 첫 번째 인수는 mysqli_result이어야한다. 그게 뭐야? 데이터베이스 쿼리의 결과입니다. – TJz
아,하지만 쿼리를 수행 할 때 [명령문 처리] (http://php.net/class.mysqli-stmt) 및 [결과] (http : //php.net/class.mysqli-result)를 반환 할 수 있습니다. ['query'] (http://php.net/mysqli.query)는 쿼리가 작동했지만 결과 세트가 없으면 부울'true'를 반환하고 오류가 발생하면 false를 반환합니다. 이것을 코드에서 처리해야합니다. – Charles