Anyone, help me here. Is my code possible? I need to assign the total number of records from the database query to the graph of javascript.

]<?php 
mysql_connect("localhost", "aaaa", "aaa") or die(mysql_error());
mysql_select_db("aaa") or die(mysql_error());
$result = mysql_query("SELECT * FROM table WHERE field ='1'") or die(mysql_error());  
while($row = mysql_fetch_array($result))
			{
				$id = $row['empId'];
						}
			

?>
<SCRIPT LANGUAGE="JavaScript1.2" SRC="graph.js"></SCRIPT>

<SCRIPT LANGUAGE="JavaScript1.2">
	
	var g = new Graph(400,200);
	
	g.scale = 1;
	<?php
	$resultCount = mysql_query("SELECT COUNT(*) FROM aa where bbb='1' AND ccc = '%egasg%'") or die(mysql_error()); 
	$count= mysql_result($resultCount,0,0);
	echo g.addRow($count,3,4,1);
	?>
	
	g.title = "haha";
	g.xLabel = "adhsashd";
	g.yLabel = "hasha";

	g.build();
</SCRIPT>

Recommended Answers

All 5 Replies

You can do this:

g.scale = 1;
<?php
$resultCount = mysql_query("SELECT COUNT(*) FROM aa where bbb='1' AND ccc = '%egasg%'") or die(mysql_error());
$count= mysql_result($resultCount,0,0);
?>
g.addRow(<?php echo $count; ?>,3,4,1);
g.title = "haha";

Thank you!! It worked!

It doesn't show any error, the graph is displayed, but it can't get the total number of record from the database.

In your query change ccc = '%egasg%'" to ccc LIKE '%egasg%'" . Other than that I can't tell what could be wrong with your query.

ok everything is working now, thanks!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.