I have two php scripts both connected to the same database but each script queries a different table. My question is how do I link these scripts so they run simultaneously. Currently they are running at the same time but completely independent of each other. For example I am working with a scatter plot in d3. One script queries information for the y axis and the other script for the x axis. This is the query in the php script for the x axis:
$myquery = "SELECT `ID`, `TITLE`, `YEAR`, `In_library` FROM `papers` where In_library = 1";
YEAR is then called in d3 and used to scale the x axis. The query for the y axis script is:
$myquery = "SELECT `ID_to`, count(*) as `counter` from `citations` group by `ID_to`";
counter is called by d3 and used as the y axis. These are the connections made in d3:
d3.json("connection1.php", function(error, data){
if (error) throw error;
data.forEach(function(d) {
d['TITLE'] = d.TITLE.toString();
d['YEAR'] = +d['YEAR'];
console.log(d['YEAR']);
})
d3.json("connection2.php", function(error, data){
//if (error) throw error;
data.forEach(function(d) {
d['counter'] = +d['counter'];
console.log(d);
})
when ran exactly as above it will just return the points correctly in regards to counter but on top of the y axis with no x values(ie x=0). But when I separate the 2 functions as in close the parentheses from the first line of each function and define all other code ie. svg, domain range etc in BOTH functions they will both execute but mutually exclusive ie. the points displayed are duplicated - one set only with y values and the other set only with x values.
My mission is to integrate these so only one set of the specified points are displayed on the graph using both the x and y axis properly.
I would be grateful for any feedback and happy to post more of the code if I havent posted enough. thanks
EDIT: Here is my php script:
<?php
$username = "root";
$password = "";
$host = "localhost";
$database="samplelit";
$server = mysql_connect($host, $username, $password);
$connection = mysql_select_db($database, $server);
$myquery = "SELECT `ID`, `TITLE`, `YEAR`,`In_library` FROM `papers` where In_library = 1";
$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);
?>
And the other script is the same with just the other query. Where do I assign the key value pairs? Thanks for the help I am very new to php and appreciate this a lot!