Im trying to print out a table with employee information, but I also want to print out a seperate table per employee on the same page. The thing is my loop is working but I canfigure out why after the first time it doesn't go to the next value in the array that is retrieved from the database. I'm coding in php and working with mysql.
Here is a bit of my code maybe some one can show me what I have missed.
$query = "Select distinct(empl_Id) from employee_involved";
//runQuery is a function that is created in the code, works properly
$queryResult = runQuery($query);
//if you use this it actually prints out the values that the while loop
//should be looping through but for some reason mysql_fetch_array($queryResult)
//won't retrieve any info after $row[0], anything after comes out blank...
//printTable($queryResult);
$num = mysql_num_rows($queryResult);
while($row = mysql_fetch_array($queryResult))
{
for($i=0;$i<$num;$i++)
{
$query1 = "Select department from employee where Id = '$row[$i]'";
$queryResult = runQuery($query1);
$deptarray = mysql_fetch_array($queryResult);
echo " ";
echo " ";
echo " ";
echo " ";
$query2 = "Select name from employee where Id = '$row[$i]'";
$queryResult = runQuery($query2);
$namearray = mysql_fetch_array($queryResult);
echo "<font size='4'><b> Employee Name: ";
echo "$namearray[0]</font>";
//if statement to perform the right select based on department
//
if ($deptarray[0] == 'Financing')
{
//there are other if statements and query's but I ommited them
//because they aren't part of the problem...
$query = "Select distinct(invoice.stocknum) AS 'Stock No.', datecreated
AS 'Date Created', basecomm AS 'BASE', ficomm AS 'F&I',
csicomm AS 'CSI', primecomm AS 'PRIME', totalcomm
AS 'TOTAL', comment AS 'COMMENT'from employee, invoice,
financecommission, employee_involved where employee.Id
= '$row[$i]' and invoice.datecreated > '$startDate' and
invoice.datecreated < '$endDate' and employee.Id =
employee_involved.empl_Id and
employee_involved.stocknum = invoice.stocknum and
employee_involved.stocknum =
financecommission.stocknum;";
}
$queryResult = runQuery($query);
echo "</br></br></br></br></br>";
//this is a function that I have defined in another class, it prints the
//table properly...
printTable($queryResult);
}
}