the following code displays output as in attachment.. it skips some of the value.. in the above output, am not getting group name for DTA. but if i add

where groupid='DTA' in query


, it displays groupname. what went wrong here? please help.. thanking in advance.

while($rowmain=mssql_fetch_array($resultmain))
{
  $course = $rowmain['GroupID'];
  //$groupname is an array
  for($i = 0, $size = sizeof($GroupName); $i <= $size; ++$i){
		if($GroupName[$i][0]== $course)
		echo "<td><font size'3'>{$GroupName[$i][1]}</font></td>";
	}
}

for off move your $size = sizeof... code what is $GroupName coming from and why is in the middle of your while loop.... never mind try this:

while($rowmain=mssql_fetch_array($resultmain)) {
    $course = $rowmain['GroupID'];
	
    //$groupname is an array
	foreach($GroupName as $key => $value) {
	    // check your values 
		echo "key= " . $key . " value = " . $value. " and course = " . $course. "<br>";
		// untested, check above output and match.
		if ($value == $course) {
                    echo "<td><font size'3'>{$value}</font></td>";
        }
    }
}
// groupname.php file contains GroupName array. 2D array.
         include 'groupname.php';
	for($i = 0; $i <= sizeof($GroupName); ++$i){
	if($GroupName[$i][0]== $course)
	echo "<td><font size'3'>{$GroupName[$i][1]}</font></td>";
	}

the output various while changing the date. looks like no error in for loop.

here is my full code. please help.

<?php 
session_start(); 
include("passwords.php"); 
check_logged(); 		
ob_start(); ?>
<html><SCRIPT LANGUAGE='javascript'>try { if (top == self) {top.location.href='main.php'; } } catch(er) { } </SCRIPT></html>  
<?php ob_end_flush(); 
	
$dblink = mssql_connect("PC1\SQLEXPRESS", "sa", "@dmin") or die("Unable to select database");
mssql_select_db("TRY");

$orgname=$_SESSION["logged"];
//$user_type=$_REQUEST["usertype"];
$fromDate = isset($_REQUEST["date3"]) ? $_REQUEST["date3"] : "";
$toDate = isset($_REQUEST["date4"]) ? $_REQUEST["date4"] : "";
//$orgname="SCSK";
$user_type='s';
//$fromDate ="2011-01-01";
//$toDate ="2011-06-30";

$start = strtotime($fromDate);
$year= date('Y ', $start);
$Jan1 = gmmktime(0, 0, 0, 1, 1, $year);
$day= date('D', $Jan1);
if($day=='Mon')
 $set = '1';
elseif($day=='Tue')
 $set ='2';
elseif($day=='Wed')
 $set ='3';
elseif($day=='Thu')
 $set ='4';
elseif($day=='Fri')
 $set ='5';
elseif($day=='Sat')
 $set ='6';
else
 $set ='7';

$query1="SELECT     COUNT(*) AS count1, Reg_Group.RegID, Reg_Group.GroupName, Reg_Group.GroupID, Reg_Group.UserType, 
                      Reg_Group.Domainid, Reg_Group.trialgroup, Reg_Group.orgid, Reg_User.ID, Reg_User.UserID, Reg_User.atype, 
                      Reg_Org.orgid AS orgzid, Reg_Org.orgname, Reg_Org.domainid AS domain, Reg_Org.create_date, 
                      Reg_Org.usertype AS usertype1, LoginLog.logintime AS logtime
FROM         Reg_Group INNER JOIN
                      Reg_User ON Reg_Group.RegID = Reg_User.RegID INNER JOIN
                      Reg_Org ON Reg_Group.orgid = Reg_Org.orgid INNER JOIN
                      LoginLog ON Reg_User.UserID = LoginLog.userid INNER JOIN
                      User_Login ON Reg_User.UserID = User_Login.UserID
WHERE    (Reg_Org.usertype = '{$user_type}') AND (Reg_Org.orgname ='{$orgname}') AND (user_login.deactivedate is null) AND (Reg_Group.GroupID !='StaffOperation')AND (Reg_Group.GroupID !='staff') AND (LoginLog.logintime BETWEEN '{$fromDate}' AND '{$toDate}')                      
GROUP BY Reg_Group.RegID, Reg_Group.GroupName, Reg_Group.GroupID, Reg_Group.UserType, Reg_Group.Domainid, 
                      Reg_Group.trialgroup, Reg_Group.orgid, Reg_User.ID, Reg_User.RegID, Reg_User.UserID, Reg_User.atype, 
                      Reg_Org.orgid, Reg_Org.orgname, Reg_Org.domainid, Reg_Org.create_date, Reg_Org.usertype, LoginLog.logintime";
?>
<style type="text/css">
table, td {
    border: 1px #CCC;
}

table {
    border-spacing: 0;
    border-style: none none solid solid;
	border-collapse: collapse;
}

td {
    border-style: solid solid none none;
    padding: 2px;
}
</style>
<?php                     
$querymain="SELECT C1.GroupID, sum(count1) total from ({$query1}) as C1 GROUP BY  C1.GroupID ";                     

echo "<table >
<tr><td><font size='3'><b>Course Code</b></font></td>
<td><font size='3'><b>Course Name</b></font></td>	        
<td><font size='3'><b>Total</b></font></td> </tr>";
$resultmain=mssql_query($querymain);
while($rowmain=mssql_fetch_array($resultmain))
{
	$course = $rowmain['GroupID'];
	$grandtotal = $rowmain['total'];
	echo "<tr><td><font size='3'>{$course}</font></td>";
	include 'groupname.php';
	for($i = 0; $i <= sizeof($GroupName); ++$i){
		if($GroupName[$i][0]== $course)
		echo "<td><font size'3'>{$GroupName[$i][1]}</font></td>";
	}
	echo"<td><font size='3'><a href=\"user.php?course=".$course."&amp;grandtotal=".$grandtotal." &amp; type=".$user_type." &amp; from=".$fromDate." &amp; to=".$toDate."\" target='frame3'>{$grandtotal}</a></font></td></tr>";
}
echo "</table>";
?>

try some more debugging. I'm also all about using a foreach. but if you must use the for($i... statement... inside of it try this:

if($GroupName[$i][0]== $course)
    echo "<td><font size'3'>{$GroupName[$i][1]}</font></td>";
} else {
   // this will only happen when groupname$i0 != 'course'  is this expected?
   echo "<td><font size'3'>Groupname= {$GroupName[$i][1]} and course={$course}
}
</font></td>";

problem solved..
value from database contains white spaces,trim added to remove it..

from :

$course = $rowmain['GroupID'];

to :

$course = trim($rowmain['GroupID']);
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.