Click here to Skip to main content
16,019,843 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
Hi,

I am getting multiple records for only one user and I need that per row I can have only one user record and on next line is the next user.

Here is the code.
(Here is the screen short user display)

here is the screen short form by table which i am using ....
Tables

<<pre lang="xml">table >
<?php
SELECT 
hs_hr_leave.leave_date,
hs_hr_leave.leave_status,
hs_hr_leave.leave_comments,
hs_hr_leavetype.leave_color,
hs_hr_employee.emp_firstname,
hs_hr_employee.emp_lastname,
hs_hr_employee.emp_middle_name,
hs_hr_compstructtree.title
FROM
hs_hr_leave
INNER JOIN hs_hr_leavetype ON hs_hr_leave.leave_type_id = hs_hr_leavetype.leave_type_id
INNER JOIN hs_hr_employee ON hs_hr_leave.emp_depment = hs_hr_employee.work_station
INNER JOIN hs_hr_compstructtree ON hs_hr_compstructtree.dept_id = hs_hr_leave.emp_depment
WHERE
hs_hr_leave.emp_depment = $depid";
$deprest = mysql_query($depsql);
if(mysql_num_rows($deprest) == 0){
?>
<tr>
<td><b>No Records to Display !</b></td>
</tr>
</table>
<?php
}else
{
while ($row = mysql_fetch_array($deprest, MYSQL_NUM)) {
    $leave_date      = $row[0];
    $leave_status    = $row[1];
    $leave_comments  = $row[2];
    $leave_color     = $row[3];
    $emp_fname       = $row[4];
    $emp_lname       = $row[5];
    $emp_mname       = $row[6];
    $demp_title      = $row[7];

    $dbD = date("d", strtotime($row[0]));
    $dbM = date("m", strtotime($row[0]));
    $dbY = date("Y", strtotime($row[0]));
    $dbuser = date("Y-m-d", mktime(0, 0, 0, $dbM, $dbD, $dbY));
    $userDates[$dbuser] = array('comments' => $leave_comments, 'status' => $leave_status,'color' => $leave_color,'deptitle' => $demp_title,'emplname' => $emp_lname);
    print_r($userDates[$dbuser]);
    }
foreach($userDates[$dbuser] as $E) { ?>
<tr>
<td width="18%" colspan="2"><strong><?php echo $userDates[$dbuser]['emplname'] ?></strong></td>
<td width="12%" colspan="2"><strong><?php echo $userDates[$dbuser]['deptitle'] ?></strong></td>
<?php
    $num = cal_days_in_month(CAL_GREGORIAN, $DMonth, $DYear); // 31
    $arrydats = array_fill (1,$num,"");
    $i=0;
                foreach($arrydats as $d)
                {
                    $i++;
                    $dates = date("Y-m-d", mktime(0, 0, 0, $DMonth,$i, $DYear));
                    $checkdate = strtotime($dates);
                                 if(isset($userDates[$dates]))
                                   {
                                    echo "<td  width='26' title='".$userDates[$dates]['comments']."' height='20px' bgcolor='#".$userDates[$dates]['color']."' align='center' valign='middle' >";
                                    if($userDates[$dates]['status'] == -1)
                                        { echo "R"; }
                                    elseif ($userDates[$dates]['status'] == 0 )
                                        { echo "C"; }
                                    elseif ($userDates[$dates]['status'] == 1 )
                                        { echo "PA"; }
                                    elseif ($userDates[$dates]['status'] == 2 )
                                        { echo "A"; }
                                    elseif ($userDates[$dates]['status'] == 3 )
                                        { echo "T"; }
                                    elseif ($userDates[$dates]['status'] == 4 )
                                        { echo "W"; }
                                    elseif ($userDates[$dates]['status'] == 5 )
                                        { echo "SH"; }
                                        }
                                    else {
                                            echo "<td width='26' height='20px' align='center' valign='middle' >".$i."</td>";
                                            }

                }
}
?>
</tr>
</tabl

e>
Posted
Updated 7-Mar-11 21:37pm
v8
Comments
Costica U 2-Mar-11 10:24am    
You already asked the same question.
http://www.codeproject.com/Questions/162088/how-to-display-only-one-user-info-per-row.aspx
vicky87 8-Mar-11 2:53am    
yes sorry i think i deleted it ...
Dalek Dave 8-Mar-11 3:37am    
Edited for Grammar and Readability.

1 solution

It seems that your problem is hs_hr_leave table. It might have multiple records for an employee.
 
Share this answer
 
Comments
vicky87 1-Mar-11 0:49am    
yes it have i am making a leave calender so multiple dates are there ...for for single user
coolestCoder 1-Mar-11 0:59am    
do you mean to have leaves for single user displayed in columns instead of rows ? Can you elaborate using sample data and output you need ?
vicky87 1-Mar-11 1:02am    
i have added the screen short
coolestCoder 1-Mar-11 1:10am    
Not able to access it from office. Will only be able to assist further when I see it. That is maybe tomorrow.
vicky87 1-Mar-11 1:15am    
ok no problem ...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900