这是将两个数据库连接在一起以生成自动 JavaScriptonclick
事件的 PHP 代码示例:
// Open website database and get list of files to download
$_db = @mysqli_connect($_dbhost, $_dbuser, $_dbpassword, $_dbname);
$data = @mysqli_query($_db, "SELECT * FROM downloads");
if ($data && @mysqli_num_rows($data)) while ($row = @mysqli_fetch_assoc($data))
{
$filename = $row['filename'];
// Open Piwik database and get goal for this file
$_pdb = @mysqli_connect($_pdbhost, $_pdbuser, $_pdbpassword, $_pdbname);
$pdata = @mysqli_query($_pdb, "SELECT idgoal FROM piwik_goal WHERE match_attribute='file' AND pattern LIKE'%$filename' AND deleted=0");
if ($pdata && $row = @mysqli_fetch_assoc($pdata))
{
$goal = $row['idgoal'];
$onclick = " onclick=\"_paq.push(['trackGoal', $goal]);\"";
}
echo "<a href="downloads/$filename"$onclick>$filename</a>";
}