나는 내 웹 사이트의 그래프 작업을하고 있습니다. 이 그래프에 다른 데이터를 표시하고 싶습니다. 4 행이있는 테이블이있는 mysql 데이터베이스가 있습니다. 이 네 개의 행을 배열에 저장하려고합니다.이 배열은 그래프에 표시됩니다.PHP에서 SQL을 사용하여 배열에 데이터 가져 오기
$transportertraindb = mysql_query("SELECT container_counter FROM transporter WHERE transporter_name = 'trein'", $db);
$transporterlorrydb = mysql_query("SELECT container_counter FROM transporter WHERE transporter_name = 'vrachtauto'", $db);
$transporterinlanddb = mysql_query("SELECT container_counter FROM transporter WHERE transporter_name = 'binnenschip'", $db);
$transporterseadb = mysql_query("SELECT container_counter FROM transporter WHERE transporter_name = 'zeeschip'", $db);
이것은 내 데이터베이스의 행입니다. 변수의 값을 변수에 저장합니다.
$data = array('Zeeschip'=>$transporterseadb, 'Binnenvaart'=>$transporterinlanddb, 'Trein'=>$transportertraindb, 'Vrachtwagen'=>$transporterlorrydb);
그리고 내 배열이됩니다.
불행히도, 이것은 원하는 결과를 제공하지 않습니다. 그래픽에서 모든 값이 동일하기 때문에 이것이 올바른 데이터를 얻지 못해서라고 생각합니다. 내 코드에서 뭔가 잘못한 것 같아. 누군가가이 문제를 도와 줄 수 있기를 바랍니다. 당신은 전체 그래프 코드를 찾을 수 아래 당신은 datas를 가져해야
<?php
include('graidlechart/graidle.php');
/array with number of tourists, by countries
$data = array('Zeeschip'=>$transporterseadb, 'Binnenvaart'=>$transporterinlanddb, 'Trein'=>$transportertraindb, 'Vrachtwagen'=>$transporterlorrydb);
// set 2 numeric arrays, one with countries (for legend), another with tourists number
$cnt = array_keys($data);
$tor = array_values($data);
// create object of graidle class (define Title)
$graph = new graidle('Representation containers of transporters');
$graph->setColor('#a7b8ed');
$graph -> setValue($tor,'p'); // set pie chart (p=pie)
$graph -> setLegend($cnt); // to add a legend
$graph -> setExtLegend(1); // to display percentage, and numbers
$graph -> setWidth(420); // graphic chart width
$graph -> create(); // create chart
$graph->carry2file('charts/', 'graphic_chart_3');
?>
데이터베이스에서 결과 집합을 가져 오는 위치는 어디입니까? 배열 값을 할당하기 전에 mysql_fetch_array 또는 mysql_fetch_assoc을 사용하고 있습니까? 그리고'mysql_ *'은 취약한 코드입니다. – Aditya
mysql_fetch_array를 사용해야합니다. – vural
@BeatAlex No :'mixed mysql_query (string $ query [, resource $ link_identifier = NULL])' – vaso123