When you use a counter in an sql query in a php script connecting a database to d3, how do you call that counter to use the values stored in it from d3? For instance I have the query
SELECT `ID_to`, count(*) as counter from `citations` group by `ID_to` ORDER BY counter desc
Now I want to call counter from d3 and use its values to scale my y axis on my scatterplot. It doesnt seem to work when I just use it as if it were a column in the table ie:
var yValue = function(d) { return d.counter;}, // data -> value
yScale = d3.scale.linear().range([height, 0]), // value -> display
yMap = function(d) { return yScale(yValue(d));}, // data -> display
yAxis = d3.svg.axis().scale(yScale).orient("left");
d3.json("connection2.php", function(error, data){
data.forEach(function(d) {
d['ID_from'] =+d['ID_from'];
d['counter'] = +d['counter'];
console.log(d);
})
How do I access these counter values and use them in d3?? Any help is much appreciated I am getting very frustrated with myself going around in circles. The error I'm getting is :
Error: Invalid value for <circle> attribute cy="NaN"
EDIT:: Here is my php script:
<?php
$username = "xxx";
$password = "xxx";
$host = "xxx";
$database="xxx";
$server = mysql_connect($host, $username, $password);
$connection = mysql_select_db($database, $server);
$myquery = "SELECT `ID_to`, count(*) as `counter` from `citations` group by `ID_to`";
$query = mysql_query($myquery);
if ( ! $query ) {
echo mysql_error();
die;
}
$data = array();
for ($x = 0; $x < mysql_num_rows($query); $x++) {
$data[] = mysql_fetch_assoc($query);
}
echo json_encode($data);
mysql_close($server);
?>
I have ran it in my browser and it returns correct results.