...

View Full Version : Need to use AJAX in my PHP/Javascript collapsable view but don't know how.



DKY
08-09-2010, 02:16 PM
I needed a collapsable view for displaying some 'drill down' analysis data. So I stumbled across this:
http://www.dynamicdrive.com/dynamicindex1/treeview/index.htm

which works beautifully and then I used a bit of PHP to do the loops for the database select statements. The problem is that the page times out unless I have a limit of like 3 on my first SQL statement because I'm doing all of these nested SQL loops within the first loop. My code in its entirety is below, is there any way that I can use AJAX to run the SQL as needed? People really only need to run the SQL on the options that they select anyway. Thanks in advance!


<?php
require("connect.php");

$connectmysql = mysql_connect($host,$user,$password) or die ($cantconnectmysqlmessage);
$db = mysql_select_db($database,$connectmysql) or die ($cantconnectdatabasemessage);

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Remarks</title>
<link href="../HighVisibility/dstyles.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="../JQueryTree/jquery.treeview.css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>
<script src="../JQueryTree/lib/jquery.cookie.js" type="text/javascript"></script>
<script src="../JQueryTree/jquery.treeview.js" type="text/javascript"></script>

<script type="text/javascript" src="../JQueryTree/demo/demo.js"></script>
</head>
<body LEFTMARGIN="0" TOPMARGIN="0" MARGINWIDTH="0" MARGINHEIGHT="0">
<div id='PageTop'>
<div id='NavLogo'></div>
</div>
<div id='PageTopBottom1'></div>
<div id='PageTopBottom2'></div>
<div id='PageTopBottom3'></div>
<div style='position: absolute; top: 145px; left: 10px; font-family:Tahoma,Arial,Helvetica,Geneva,sans-serif; font-size:small;'>
<?php
echo "<ul id='navigation'>\n";
$Disp1Query = "SELECT DISTINCT GROUPCD, (ROUND(((sum(fl)/sum(tl))*100),2)) as GSFILL, GRPDESC FROM tblpartpfil GROUP BY GROUPCD ORDER BY GSFILL ASC limit 2";
$Disp1Result = mysql_query($Disp1Query) or die(mysql_error().'<br />'.$Disp1Query);
while ($Row1 = mysql_fetch_assoc($Disp1Result))
{
if($Row1['GROUPCD']==""){
$GroupTitle = "<table border='0' bordercolor='#000000' cellpadding='0' cellspacing='0'><tr><td width='40'>00</td><td width='300'>BLANK</td><td>".$Row1['GSFILL']."%</td></tr></table>\n";
}else{
$GroupTitle = "<table border='0' bordercolor='#000000' cellpadding='0' cellspacing='0'><tr><td width='40'>".$Row1['GROUPCD']."</td><td width='300'>".$Row1['GRPDESC']."</td><td>".$Row1['GSFILL']."%</td></tr></table>\n";
}
echo "<li>".$GroupTitle."\n";
$Disp2Query = "SELECT DISTINCT NOUNCD, (ROUND(((sum(fl)/sum(tl))*100),2)) as NSFILL, NOUNDESC FROM tblpartpfil WHERE GROUPCD = '".$Row1['GROUPCD']."' GROUP BY NOUNCD ORDER BY NSFILL ASC";
$Disp2Result = mysql_query($Disp2Query) or die(mysql_error().'<br />'.$Disp2Query);
while ($Row2 = mysql_fetch_assoc($Disp2Result))
{
if($Row2['NOUNCD']==""){
$NounTitle = "<table border='0' bordercolor='#000000' cellpadding='0' cellspacing='0'><tr><td width='50'>0000</td><td width='300'>BLANK</td><td>".$Row2['NSFILL']."%</td></tr></table>\n";
}else{
$NounTitle = "<table border='0' bordercolor='#000000' cellpadding='0' cellspacing='0'><tr><td width='50'>".$Row2['NOUNCD']."</td><td width='300'>".$Row2['NOUNDESC']."</td><td>".$Row2['NSFILL']."%</td></tr></table>\n";
}
echo "<ul style='margin:0px; padding:0px;'>\n";
echo "<li>".$NounTitle."\n";
$Disp3Query = "SELECT DISTINCT ADJCD, (ROUND(((sum(fl)/sum(tl))*100),2)) as ASFILL, ADJDESC FROM tblpartpfil WHERE GROUPCD = '".$Row1['GROUPCD']."' AND NOUNCD = '".$Row2['NOUNCD']."' GROUP BY ADJCD ORDER BY ASFILL ASC";
$Disp3Result = mysql_query($Disp3Query) or die(mysql_error().'<br />'.$Disp3Query);
while ($Row3 = mysql_fetch_assoc($Disp3Result))
{
if($Row3['ADJCD']==""){
$AdjTitle = "<table border='0' bordercolor='#000000' cellpadding='0' cellspacing='0'><tr><td width='50'>0000</td><td width='300'>/BLANK</td><td>".$Row3['ASFILL']."%</td></tr></table>\n";
}else{
$AdjTitle = "<table border='0' bordercolor='#000000' cellpadding='0' cellspacing='0'><tr><td width='50'>".$Row3['ADJCD']."</td><td width='300'>".$Row3['ADJDESC']."</td><td>".$Row3['ASFILL']."%</td></tr></table>\n";
}
echo "<ul>\n";
echo "<li>".$AdjTitle."\n";
$Disp4Query = "SELECT DISTINCT a.NAV_PN, (ROUND(((sum(a.fl)/sum(a.tl))*100),2)) as NAV_PN_SFILL, b.DESCR FROM tblpartpfil a LEFT JOIN tblvisiblepsdbsumoneweekpfil b ON a.NAV_PN=b.NAV_PN WHERE a.GROUPCD = '".$Row1['GROUPCD']."' AND a.NOUNCD = '".$Row2['NOUNCD']."' AND a.ADJCD = '".$Row3['ADJCD']."' GROUP BY a.NAV_PN ORDER BY NAV_PN_SFILL ASC";
$Disp4Result = mysql_query($Disp4Query) or die(mysql_error().'<br />'.$Disp4Query);
while ($Row4 = mysql_fetch_assoc($Disp4Result))
{
$NAV_PN_Info = "<table border='0' bordercolor='#000000' cellpadding='0' cellspacing='0'><tr><td width='150'>".$Row4['NAV_PN']."</td><td width='400'>".$Row4['DESCR']."</td><td>".$Row4['NAV_PN_SFILL']."%</td></tr></table>\n";
echo "<ul>\n";
echo "<li>".$NAV_PN_Info."</li>\n";
echo "</ul>\n";
} echo "</li>\n";
echo "</ul>\n";
}
echo "</li>\n";
echo "</ul>\n";
}
echo "</li>\n";
}
echo "</ul>\n";
?>
</div>
</body>
</html>

DKY
08-10-2010, 02:55 PM
Anyone? I've found this on w3c's website:
http://w3schools.com/php/php_ajax_database.asp

Which I get but I can't figure out how to incorporate this into my page. Which js file would I put this function code in?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum