Link to home
Start Free TrialLog in
Avatar of sukotto100
sukotto100

asked on

Creating variable tree in php for javascript to read (NOOB)

 I am trying to duplicate the variable tree that starts at line 52 via php rather than hard coding it. I am able to generate the top level (school), now I figured I could put another loop in the do while statement, but I am getting an infinite loop. I have tried a million ways to do this, but to no avail.
I also have a feeling there is a way I can do this with one db query.

Any help would be appreciated.
Scott

This worked:
<br /><script language="JavaScript">
 totalR = 9;
 var schools = new Array();
aa:{
ahs:{
biz:{
dent:{
edu:{
eng:{
las:{
n:{
up:{
</script>

Adding the loop went awry:

<br /><script language="JavaScript">
totalR = 9;
 var schools = new Array();
aa:{
Health Information Mgmt.:
Health Information Mgmt.:
Health Information Mgmt.:
Health Information Mgmt.:
Health Information Mgmt.:
Health Information Mgmt.:

<?php require_once('../Connections/ids499.php'); ?>
<?php
//query selects departments for header of each major
mysql_select_db($database_ids499, $ids499); //db, connection
$query_Recordset1 = "select distinct deptName_id from gradByMaj"; //query string
$Recordset1 = mysql_query($query_Recordset1, $ids499) or die(mysql_error()); //
$row_Recordset1 = mysql_fetch_assoc($Recordset1); //query exe?
$totalRows_Recordset1 = mysql_num_rows($Recordset1); //count rows

//query selects majors and quantities
mysql_select_db($database_ids499, $ids499); //db, connection
$query_Recordset2 = "select major_id, qGrad, deptName_id, sYear from gradByMaj"; //query string
$Recordset2 = mysql_query($query_Recordset2, $ids499) or die(mysql_error()); //
$row_Recordset2 = mysql_fetch_assoc($Recordset2); //query exe?
$totalRows_Recordset2 = mysql_num_rows($Recordset2); //count rows
?>
<html>
<head>
<script type="text/javascript" src="../protovis-r3.2.js"></script>
<link href="/ids499/ex.css" rel="stylesheet" type="text/css">
<style type="text/css">
#fig {  width: 1000px;}

</style>
<title>Treemap: 2010 Graduation by School, Degree</title>
</head>
<body>

<div id = "title">Treemap of Degrees in 2010 by Department</div><br />

<?php echo "<br />" ?>
<?php $colors = array("orange", "green", "blue", "red");
echo "<script language=\"JavaScript\">\n";
echo " totalR = $totalRows_Recordset1;\n";
echo " var schools = new Array();\n";
do {
echo $row_Recordset1['deptName_id'];
echo ":{\n"; 

/* pulls second level, with majors and numbers. Not working */
do {
echo $row_Recordset2['major_id'];
echo ":\n"; 
} while ($row_Recordset2['deptName_id'] = $row_Recordset1['deptName_id']);


} while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));
echo "</script>\n"; ?>
<div id="fig">
<script type="text/javascript+protovis">

var tree = {
ahs:{
health:{
	"Health Information Mgmt":20,
  	"Kinesiology":144,
  	"Nutrition":27,
  			},
nurse:{
		"Nursing":158,
			},
upa:{
		"Urban & Public Affairs":22,
			},
 	},

Open in new window

Avatar of Lukasz Chmielewski
Lukasz Chmielewski
Flag of Poland image

do {
....
do {
...
} while ($row_Recordset2['deptName_id'] = $row_Recordset1['deptName_id']);
} while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));

I think this is equal all the time
$row_Recordset2['deptName_id'] = $row_Recordset1['deptName_id']
and so the infinite loop

I'm not yet sure about this (still trying to decode the snippet :P) but this seems to be the problem.
Avatar of sukotto100
sukotto100

ASKER

Sorry if it is a mess(>.<); Here is a sample of the table data:

deptName_id| major_id| sYear| qGrad
ahs|      Health Information Mgmt.|      2004|      17
ahs|      Kinesiology|      2004|      78
ahs|      Nutrition|      2004|      18
ahs|      Phys. Ed.|      2004|      0
aa|      Architectural Studies|      2004|      92
aa|      Art Education|      2004|      11
aa|      Art History|      2004|      25
aa|      Electronic Visualization|      2004|      0
ASKER CERTIFIED SOLUTION
Avatar of Lukasz Chmielewski
Lukasz Chmielewski
Flag of Poland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Awesome!! thanks! This really helps me learn as well.
Thanks. It was a long shot, I was notable to get the visualization with protovis, so I was not sure if that did it. Cheers.