0
我試圖結合d3,mysql php Tutorial。 我想用mysql來存儲數據,並使用d3表來顯示結果。 繼教程之後,我成功連接了sql,並將其顯示出來。d3.js如何將參數傳遞給php查詢條件
但是,在我的示例中,queryData.php
中的sql的where
條件是硬編碼的。 如下所示:WHERE pathwayID='1643685' && symbol='VIF'
我需要將參數'1643685'和'VIF'從d3文件傳遞到php文件,該怎麼辦? 我該如何修改queryData.php,謝謝。
d3 file
d3.json("queryData.php", function(error, jsonData) {
....
});
queryData.php
<?php
error_reporting(E_ALL^E_DEPRECATED);
// load in mysql server configuration (connection string, user/pw, etc)
include 'mysqlConfig.php';
// connect to the database
@mysql_select_db($database) or die("Unable to select database");
//Query
$myquery = "
SELECT `pathwayID`, `proteinID`, `uniprotID`, `symbol`, `displaySymbol`, `reactomeID`, `cellularLocation` FROM `protein` WHERE pathwayID='1643685' && symbol='VIF'
";
$result = mysql_query($myquery);
if (! $result) {
echo mysql_error();
die;
}
$data = array();
for ($x = 0; $x < mysql_num_rows($result); $x++) {
$data[] = mysql_fetch_assoc($result);
}
echo json_encode($data);
mysql_close();
?>
mysqlConfig.php
<?php
error_reporting(E_ALL^E_DEPRECATED);
$username="root"; //replace with your mySql username
$password=""; //replace with your mySql password
$database="pathway"; //replace with your mySql database name
$host="localhost"; //replace with the name of the machine your mySql runs on
$connection=mysql_connect($host,$username,$password);
?>