我有一些关于mysql的数据,其中用户注册了各个区域的数据。现在我需要在区域的基础上对它们进行分组并将它们呈现在图表上。我从谷歌图表得到了反对。我的问题是如何将数据组分组。
示例:
user1 district1
user2 district2
user3 district1
user4 district1
user5 district2
现在我需要以下数据:
district1=>3
district2=>2
从MySql检索数据。任何人都可以帮助PHP代码或任何SQL查询来检索这样的数据,这样我就可以在js上传递对象以形成图形。
答案 0 :(得分:1)
您需要从数据库中选择分区和用户数,然后按地区分组:
SELECT COUNT(user),district FROM yourtable GROUP BY district;
答案 1 :(得分:0)
这应该有用(当然你需要根据需要调整列名和表名):
$('input[type=file]#imagencabecera').change(function(){
var file = (this.files[0].name).toString();
var type = (this.files[0].type).toString();
var reader = new FileReader();
console.log(type);
$('#file-info').text('');
$('#file-info').text(file);
reader.onload = function (e){
$('#filepreview img').attr('src', e.target.result);
}
reader.readAsDataURL(this.files[0]);
});
function checkFileType(file){
if (window.FileReader && window.Blob)
// All the File APIs are supported. Si soporta HTML5 FileReader y Blob
{
var slice = file.slice(0,4); // Get the first 4 bytes of a file
var reader = new FileReader(); // Create instance of file reader. It is asynchronous!
reader.readAsArrayBuffer(slice); // Read the chunk file and return to blob
reader.onload = function(e) {
var buffer = reader.result; // The result ArrayBuffer
var view = new DataView(buffer); // Get access to the result bytes
var signature = view.getUint32(0, false).toString(16); // Read 4 bytes, big-endian,return hex string
switch(signature) // Every file has a unique signature, we can collect them and create a data lib
{
case "89504e47": file.verified_type = "image/png"; break;
case "47494638": file.verified_type = "image/gif"; break;
case "FFd8FFe0": file.verified_type = "image/jpeg"; break;
case "FFd8FFe1": file.verified_type = "image/jpeg"; break;
case "FFd8FFe2": file.verified_type = "image/jpeg"; break;
case "FFd8FFe3": file.verified_type = "image/jpeg"; break;
case "FFd8FFe8": file.verified_type = "image/jpeg"; break;
default: file.verified_type = 0;
}
}
}
else
// File and Blob are not supported
{
}
}