我使用php
制作了条形图,javascript
和mysql
实际上是动态图形。
但它没有正常工作它只显示数据库的最后一列记录。
我希望它显示整个请求的列记录。我不知道出了什么问题。
<!DOCTYPE HTML>
<html>
<head>
<title> graph </title>
</head>
<body>
<?php
$psbhostemailaddress = "thepsbhostemailaddress"; //EDIT ME
$roothostname = "localhost";
$psbhostusername = "pedy"; //EDIT ME
$psbhostpassword = "9eKH8qrdm3xYHTJz"; //EDIT ME
$psbhostdatabasename = "ped"; //EDIT ME
mysql_connect("".$roothostname."","".$psbhostusername."","".$psbhostpassword."") or die(mysql_error());
mysql_select_db("".$psbhostdatabasename."") or die(mysql_error());
$post_type=array(); $ID=array();
$table= wp_posts;
$t=$table;
if(strlen($table) > 0){
$exists = mysql_query("SHOW TABLES LIKE '$table'") or die(mysql_error());
$num_rows = mysql_num_rows($exists);
if($num_rows>0){
$sql=mysql_query("SELECT * FROM $table");
if(mysql_num_rows($sql)>0){
unset($table);
while($row = mysql_fetch_array($sql)){
$m=htmlentities(stripslashes($row['post_type']), ENT_QUOTES);
$a=htmlentities(stripslashes($row['ID']), ENT_QUOTES);
array_push ($ID, $a);
array_push ($post_type, $m);
}
$biggest=max($ID);
mysql_close();}}
else{echo '<script language="javascript">alert("No such table.");window.location="front-page.php";</script>;';}
}
?>
<script language = "javascript">
var m = <?php echo json_encode($post_type); ?>;
var a = <?php echo json_encode($ID); ?>;
var b = <?php echo json_encode($biggest); ?>;
var t = <?php echo json_encode($t); ?>;
var r = b / 100;
if (a.length > 0 && m.length > 0) {
for (var i = 0; i < a.length; i++) {
var divTag = document.createElement("div");
divTag.id = "a" + i;
divTag.setAttribute("align", "center");
divTag.style.marginLeft = (i * 78 + 20) + "px";
divTag.style.position = "absolute";
divTag.style.bottom = 100 + "px";
divTag.style.height = (a[i] / r) + "px";
divTag.className = "aDiv";
divTag.innerHTML = a[i];
document.body.appendChild(divTag);
}
for (var i = 0; i < a.length; i++) {
var divTag = document.createElement("div");
divTag.id = "b" + i;
divTag.setAttribute("align", "center");
divTag.style.marginLeft = (i * 78 + 20) + "px";
divTag.style.position = "absolute";
divTag.style.bottom = 70 + "px";
divTag.style.height = 30 + "px";
divTag.className = "bDiv";
divTag.innerHTML = m[i];
document.body.appendChild(divTag);
}
document.write("<div id='label'><h1>" + t + "</h1></div><div id='myid' style='min-width:" + (a.length * 80) + "px; width:" + (a.length * 80) + "px'> </div>");
} </script>
</body>
</html>
并且此代码在我的Wordpress
主题中运行,我将其插入到html中,因为它很清楚。