通过PHP从MySQL获取全部数据? [英] FLOT data from MySQL via PHP?
问题描述
下午好,我看了FLOT网站的示例,并用谷歌搜索,但找不到任何有关如何将数据从MySQL提取到FLOT的详细步骤.
Good afternoon, I have looked at the FLOT website examples and googled but just cannot find anywhere with detailed steps on how to pull data from MySQL into FLOT.
当前,我有一个带有记录集的php页面,该记录集存储了mysql表中的所有记录,列为日期,用户&成本.我是否需要创建一个数据表以在页面中显示所有这些记录?
Currently I have a php page with a recordset that stores all records from a mysql table, columns are date, user & cost. Do I need to create a data table to display all these records in the page?
当对上面的数据进行排序时,我将如何将这些数据称为FLOT,我知道对于任何开发人员来说,它可能非常明显,但我今天找不到该信息.
When above is sorted how would I call that data into FLOT, I know its probably very obvious to any develiopers out there but I just cant find the info today.
感谢您提供的任何帮助/指标.
Thanks for any help/pointers offered.
推荐答案
在flot中查看AJAX示例文档.
Look the AJAX example in the flot documentation.
基本上,这些步骤是:
1.)从数据库中提取.
1.) Pull from database.
2.)将数据放入以下形式的PHP键/值数组中:
2.) Place data in PHP key/value array of form:
$dataSet1 = Array();
$dataSet1['label'] = 'Customer 1';
$dataSet1['data'] = Array(Array(1,1),Array(2,2)); // an array of arrays of point pairs
$dataSet2 = Array();
$dataSet2['label'] = 'Customer 2';
$dataSet2['data'] = Array(Array(3,3),Array(4,5)); // an array of arrays of point pairs
$returnArray = Array($dataSet1, $dataSet2);
3.)返回您的JavaScript,将此JSON编码的字符串作为JS变量获取:
3.) Back in your javascript, get this json encoded string as JS variable:
var data = <?php echo json_encode($arr); ?>;
4.)返回您的JavaScript,使用该数据变量调用flot plot方法:
4.) Back in your javascript, call the flot plot method with that data variable:
$.plot($("#placeholder"), data, options);
这篇关于通过PHP从MySQL获取全部数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!