I made a bar graph using php
and javascript
and mysql
actually a dynamic graph.
but it doesn't work correctly it just shows last column record of database.
I want it shows whole requested column records. I don't know what is wrong.
<!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>
and this code is running in my Wordpress
theme I inserted it into html because it be clear.