hi,
I am having this little problem…
I have a template and i fill it with the results i get from some sql queries. the problem is that I have some nested while loops and sql queries and when I parse the needed values I get as a result all the previous values plus the new ones. In my case I am trying to extract all the committees a user is member of and at the same time all the announcements and the members that are linked to each committee.
so here is the code….
[CODE]
<?php
session_start();
if(!session_is_registered(“authenticated”)){
header(“location:login.php”);
}
include(“include/config.inc.php”);
include(“include/functions.php”);
include(“Classes/class.FastTemplate.php3”);
$tpl=new FastTemplate(“templates”);
$tpl->define(array(“index”=>”main_tpl.tpl”,
“ver_nav_dep”=>”vertical_nav_dep.tpl”,
“ver_nav_pd”=>”vertical_nav_pd.tpl”,
“ver_nav_head”=>”vertical_nav_head_secr.tpl”,
“table_pub”=>”table_pub.tpl”,
“row_title_pub”=>”row_title_pub.tpl”,
“row_pub”=>”row_pub.tpl”,
“table_auth”=>”table_auth.tpl”,
“row_title_auth”=>”row_title_auth.tpl”,
“row_auth”=>”row_auth.tpl”,
“table_preview_announce”=>”table_preview_announce.tpl”,
“table_committee_pub”=>”table_committee_pub.tpl”,
“row_committee_pub”=>”row_committee_pub.tpl”,
“row_committee_member_pub”=>”row_committee_member_pub.tpl”,
“row_committee_announce_pub”=>”row_committee_announce_pub.tpl”,
“table_committee”=>”table_committee.tpl”,
“rows_committee”=>”rows_committe.tpl”,
“rows_committee_member”=>”rows_committe_memeber.tpl”,
“rows_committee_announce”=>”rows_committee_announce.tpl”));
$con=mysql_connect($dbServer, $dbUser, $dbPass)
or exit(“<html>
<head>
<meta http-equiv=”Content-Type” content=”text/html;charset=windows-1253″>
<link rel=”stylesheet” type=”text/css” href=”../../styles/lh.css”>
</head>
<body>
<h2 align=center>Σφάλμα κατά τη σύνδεση με τη Βάση Δεδομένων</h2>
</body>
</html>”);
//valid assignment for insert content
$author_id=$_SESSION[“id”];
if($_SESSION[“type”]==”admin” || $_SESSION[“type”]==”pub”){
$active=1;
}
else{
$active=0;
}
if(isset($_REQUEST[“load”])){
$head_id=$_SESSION[“id”];
$tpl->assign(“{USER}”,$_SESSION[“username”]);
$page_name=”Επιτροπές”;
$tpl->assign(“{PAGE_NAME}”,$page_name);
switch($_SESSION[“group”]){
case “Melos DEP”:
$tpl->assign(“{H_NAVIGATION}”,”);
$tpl->assign(“{TREE}”,”treemenu1″);
$tpl->parse(“{V_NAVIGATION}”,”.ver_nav_dep”);
break;
case “PD 407/80”:
$tpl->assign(“{H_NAVIGATION}”,”);
$tpl->assign(“{TREE}”,”treemenu1″);
$tpl->parse(“{V_NAVIGATION}”,”.ver_nav_pd”);
break;
}//end switch
//show only committees where professor is head or member
$sql=”SELECT DISTINCT c.id as id,
c.title_gr as title,
c.active as active
FROM committee c,
committee_members cm
WHERE c.head_id=’$head_id’
OR (c.id=cm.committee_id AND cm.member_id=’$head_id’)”;
$res=mysql_db_query($dbDatabase,$sql);
if(mysql_num_rows($res)==’0′){
$tpl->assign(“{CONTENT}”,”<center><h3>Δεν υπάρχουν επιτροπές.</center></h3>”);
}
if ($res && mysql_num_rows($res)){
while($result=mysql_fetch_array($res)){
//$comm_array[]=$result[“id”];
//find committee members
$sql1=”SELECT DISTINCT p.inter_name_gr as name, c.active as active, c.memid as memid
FROM personnel p, (SELECT member_id as memid, active as active
FROM committee_members
WHERE committee_id='”.$result[“id”].”‘) c
WHERE p.id=memid”;
$res1=mysql_db_query($dbDatabase,$sql1);
if($res1 && mysql_num_rows($res1)){
while($result1=mysql_fetch_array($res1)){
$name=stripslashes($result1[“name”]);
$memid=$result1[“memid”];
$tpl->assign(“{NAME_MEMBER}”,$name);
$tpl->assign(“{DEL_MEM}”,”<a href=”committee.php?delete=member&id=”.$memid.”” onclick=”return confirmlink(‘Θέλετε να διαγραφτεί το συγκεκριμένο μέλος;’,this)”><img width=”15″ height=”16″ src=”images/del2.png” alt=”Διαγραφή” title=”Διαγραφή” border=”0″/></a>”);
if($result1[“active”]==”0″){
$tpl->assign(“{ACTIVE_ΜΕΜ}”,”<a href=”committee.php?active=member&act=yes&id=”.$memid.”” onclick=”return confirmlink(‘Θέλετε να ενεργοποιήσετε τo συγκεκριμένο μέλος;’,this)”><img width=”15″ height=”16″ src=”images/stop2.png” alt=”Κάντε κλικ για ενεργοποίηση” title=”Κάντε κλικ για ενεργοποίηση” border=”0″/></a>”);
}
if($result1[“active”]==”1″){
$tpl->assign(“{ACTIVE_MEM}”,”<a href=”committee.php?active=member&act=no&id=”.$memid.”” onclick=”return confirmlink(‘Θέλετε να απενεργοποιήσετε το συγκεκριμένο μέλος;’,this)”><img width=”15″ height=”16″ src=”images/apply2.png” alt=”Κάντε κλικ για απενεργοποίηση” title=”Κάντε κλικ για απενεργοποίηση” border=”0″/></a>”);
}
$tpl->parse(“{COMMITTEE_MEMBER_ROWS}”,”.rows_committee_member”);
}//end while result1
}//end if res1 true
$sql2=”SELECT DISTINCT ca.id as id, ca.title_gr as title, ca.active as active
FROM committee_announcement ca
WHERE ca.committee_id='”.$result[“id”].”‘”;
$res2=mysql_db_query($dbDatabase,$sql2);
$result2=””;
if($res2 && mysql_num_rows($res2)){
while($result2=mysql_fetch_array($res2)){
$title=stripslashes($result2[“title”]);
$id=$result2[“id”];
$active=$result2[“active”];
$tpl->assign(“{TITLE_ANN}”,$title);
$tpl->assign(“{MOD_ANN}”,”<a href=”committee.php?edit=announce&id=”.$id.””><img width=”15″ height=”16″ src=”images/edit2.png” alt=”Αλλαγή” title=”Αλλαγή” border=”0″/></a>”);
$tpl->assign(“{DEL_ANN}”,”<a href=”committee.php?delete=announce&id=”.$id.”” onclick=”return confirmlink(‘Θέλετε να διαγραφτεί η συγκεκριμένη ανακοίνωση;’,this)”><img width=”15″ height=”16″ src=”images/del2.png” alt=”Διαγραφή” title=”Διαγραφή” border=”0″/></a>”);
if($active==”0″){
$tpl->assign(“{ACTIVE_ANN}”,”<a href=”committee.php?active=announce&act=yes&id=”.$id.”” onclick=”return confirmlink(‘Θέλετε να ενεργοποιήσετε τη συγκεκριμένη ανακοίνωση;’,this)”><img width=”15″ height=”16″ src=”images/stop2.png” alt=”Κάντε κλικ για ενεργοποίηση” title=”Κάντε κλικ για ενεργοποίηση” border=”0″/></a>”);
}
if($active==”1″){
$tpl->assign(“{ACTIVE_ANN}”,”<a href=”committee.php?active=announce&act=no&id=”.$id.”” onclick=”return confirmlink(‘Θέλετε να απενεργοποιήσετε τη συγκεκριμένη ανακοίνωση;’,this)”><img width=”15″ height=”16″ src=”images/apply2.png” alt=”Κάντε κλικ για απενεργοποίηση” title=”Κάντε κλικ για απενεργοποίηση” border=”0″/></a>”);
}
$tpl->parse(“{COMMITTEE_ANNOUNCE_ROWS}”,”.rows_committee_announce”);
}//end while result2
}//end if res2 true
else if(mysql_num_rows($res2)==’0′){
$tpl->assign(“{COMMITTEE_ANNOUNCE_ROWS}”,”<tr> <td class=”boxContentCell” colspan=”4″>Δεν έχουν αναρτηθεί ανακοινώσεις για τη συγκεκιμένη επιτροπή.</td></tr>”);
}//end else if
$tpl->assign(“{ID}”,$result[“id”]);
$tpl->assign(“{COMMITTEE_NAME}”,stripslashes($result[“title”]));
$tpl->assign(“{EDIT_COMMITTEE}”,”<a href=”committee.php?edit=committee&id=”.$result[“id”].””><img width=”15″ height=”16″ src=”images/edit3.png” alt=”Αλλαγή” title=”Αλλαγή” border=”0″/></a>”);
$tpl->assign(“{DELETE_COMMITTEE_FULL}”,”<a href=”committee.php?delete=committee&id=”.$result[“id”].”” onclick=”return confirmlink(‘Διαγράφοντας τη συγκεκριμένη επιτροπή θα διαγραφούν όλες οι ανακοιώσεις και όλα τα μέλη της επιτροπής αυτής. Θέλετε να συνεχίσετε;’,this)”><img width=”15″ height=”16″ src=”images/del3.png” alt=”Διαγραφή” title=”Διαγραφή” border=”0″/></a>”);
if($result[“active”]==”0″){
$tpl->assign(“{ACTION_COMMITTEE_FULL}”,”<a href=”committee.php?active=committee&act=yes&id=”.$result[“id”].”” onclick=”return confirmlink(‘Ενεργοποιώντας τη συγκεκριμένη επιτροπή θα ενεργοποιηθούν όλες οι ανακοιώσεις και όλα τα μέλη της επιτροπής αυτής. Θέλετε να συνεχίσετε;’,this)”><img width=”15″ height=”16″ src=”images/stop3.png” alt=”Κάντε κλικ για ενεργοποίηση” title=”Κάντε κλικ για ενεργοποίηση” border=”0″/></a>”);
}
if($result[“active”]==”1″){
$tpl->assign(“{ACTION_COMMITTEE_FULL}”,”<a href=”committee.php?active=committee&act=no&id=”.$result[“id”].”” onclick=”return confirmlink(‘Απενεργοποιώντας τη συγκεκριμένη επιτροπή θα απενεργοποιηθούν όλες οι ανακοιώσεις και όλα τα μέλη της επιτροπής αυτής. Θέλετε να συνεχίσετε;’,this)”><img width=”15″ height=”16″ src=”images/apply3.png” alt=”Κάντε κλικ για απενεργοποίηση” title=”Κάντε κλικ για απενεργοποίηση” border=”0″/></a>”);
}
$tpl->parse(“{ROWS}”,”.rows_committee”);
}//end while $result
$tpl->parse(“{CONTENT}”,”table_committee”);
}//end if res true
$tpl->parse(“MAIN”,”index”);
$tpl->FastPrint();
}
?>
what happens for example for the announcements is I get the announcements for the first committee and they appear correct, but when it comes to the announcements of the second committee i get as a result the announcements of the first plus the announcements of the second. the announcement of third committee are all announcements from both 1 and 2 plus her own…. Any suggestion what to do to fix this …
Thanx in advance
Yona