report generate from database into text file
Hello all
I am trying to do--Attendance of the month march
and i want format for text file is like
employeecode 1 2 3 4 5 6 7 8------30
E01 A P P P p P P P
E02
--
--
--
I m using mysql database. My tables for this is :
for employee code at0310..... for dates m using table mar10
but for employee present and absent i need to print it by coding
but couldnt understand how to do it......plz help me out .. the code dat i m using is not correct.........
dat display date and ecode but ecode is correct like shown above but dates are not like dat and how i dont hw print A and P ....
<?
$myFile = "att.txt";
$conn = mysql_connect("localhost", "root", "root")
or die("Could not connect: ".mysql_error());
mysql_select_db("master",$conn)
or die("Could not select db: " . mysql_error());
$fhandle = fopen($myFile, 'w')
or die("Error opening file.");
$res = mysql_query("SELECT emp_company.ecode, mar10.Date FROM emp_company,mar10 ");
)
while ($row = mysql_fetch_assoc($res))
fwrite ($fhandle, "{$row['ecode']}\t {$row['Date']}\t \r\n");
fclose($fhandle);
echo "Report Generated ";
?>
preetg
Junior Poster in Training
95 posts since Jan 2010
Reputation Points: 11
Solved Threads: 4
CREATE TABLE emp_company (
ecode varchar(15) NOT NULL default '',
ename varchar(15) NOT NULL default '',
ecom varchar(15) NOT NULL default '',
edoj date NOT NULL default '0000-00-00',
edol date NOT NULL default '0000-00-00',
edpt varchar(15) NOT NULL default '',
esubdpt varchar(15) NOT NULL default '',
eesicode varchar(15) NOT NULL default '',
epf varchar(17) NOT NULL default '',
ecardno varchar(20) NOT NULL default '',
ebank int(15) NOT NULL default '0',
PRIMARY KEY (ecode)
) TYPE=MyISAM;
TABLE:----mar10
CREATE TABLE mar10 (
Date int(5) NOT NULL default '0'
) TYPE=MyISAM;
preetg
Junior Poster in Training
95 posts since Jan 2010
Reputation Points: 11
Solved Threads: 4
i will get info about present or absent of employee through at0310 table. ecode from employee table and that ecode i will find out into at0310 table whether that ecode is present in at0310(attendance table) table or not whr den further i match dat ecode with date and time into at0310 table............ bez at0310 table having all fields dat download from attendance machine which having daily info about employee's......i hope you understand this...........
preetg
Junior Poster in Training
95 posts since Jan 2010
Reputation Points: 11
Solved Threads: 4
this is attendance table----------
CREATE TABLE at0310 (
ecardno varchar(20) NOT NULL default '',
atdate date NOT NULL default '0000-00-00',
attime time NOT NULL default '00:00:00',
IO varchar(10) NOT NULL default '',
serialno int(15) NOT NULL default '0',
cardrd varchar(15) NOT NULL default '',
ecode varchar(15) NOT NULL default ''
) TYPE=MyISAM;
IO is for IN and Out time for employees........
preetg
Junior Poster in Training
95 posts since Jan 2010
Reputation Points: 11
Solved Threads: 4
thanks bhanuparkash for reply and getting time for reply............
i hope my prob will solve soon......... i used ur code...
i got these warnings-
Warning: Supplied argument is not a valid MySQL result resource in c:\apache\htdocs\newhr\danihelp.php on line 8
Warning: Supplied argument is not a valid MySQL result resource in c:\apache\htdocs\newhr\danihelp.php on line 13
i try to resolve it but cant........... plz help me out............
preetg
Junior Poster in Training
95 posts since Jan 2010
Reputation Points: 11
Solved Threads: 4
i already established connection ..... but also warnings
preetg
Junior Poster in Training
95 posts since Jan 2010
Reputation Points: 11
Solved Threads: 4
m waiting for your reply..........i m very close to the solution.....but some warning msgs stucked me.....
Warning: Supplied argument is not a valid MySQL result resource in c:\apache\htdocs\newhr\danihelp.php on line 20
Warning: Supplied argument is not a valid MySQL result resource in c:\apache\htdocs\newhr\danihelp.php on line 20
Warning: Supplied argument is not a valid MySQL result resource in c:\apache\htdocs\newhr\danihelp.php on line 20
preetg
Junior Poster in Training
95 posts since Jan 2010
Reputation Points: 11
Solved Threads: 4
hi dear.............
we hav already made some modifications.......after made all the changes then got these warnings....plz help me out...here is the edited code..........
<?php
mysql_connect("localhost","root","root");
mysql_select_db("master");
$dates = array();
$employee = array();
$attendance_record = array();
$getdates = "select * from mar10 order by Date";
$dates_resultset = mysql_query($getdates);
while ($dates_data = mysql_fetch_assoc($dates_resultset))
{
$dates[] = $dates_data['Date'];
}
$get_employee = "select * from emp_company";
$employee_resultset = mysql_query($get_employee);
while ($employee_data = mysql_fetch_assoc($employee_resultset))
{
$get_attendance = "select * from at0310 where ecode=".$employee_data['ecode']." and atdate in (".implode(",",$dates).") order by atdate" or die(mysql_error());
$employee[$employee_data['ecode']] = $employee_data['ename'];
$attendance_resultset = mysql_query($get_attendance);
while ($attendance_data = mysql_fetch_assoc($attendance_resultset))
{
// FOR SCENARIO 1
$attendance_record[$employee_data['ecode']][$attendance_data['atdate']]['attendance'] = "P";
//if ($attendance_data['IO'] != "")
//{
//$attendance_record[$employee_data['ecode']][$attendance_data['atdate']]['attendance'] = "P";
//}
//else
//{
//$attendance_record[$employee_data['ecode']][$attendance_data['atdate']]['attendance'] = "A";
//}
}
}
$tabledata = "";
$tabledata .= "Empcode Name \t";
foreach ($dates as $key => $value) {
$tabledata .= $value." \t";
}
$tabledata .= "\r\n";
foreach ( $employee as $emp_key => $emp_value )
{
$tabledata .= $emp_key."/".$emp_value;
foreach ( $dates as $dates_key => $dates_value )
{
$tabledata .= "\t";
if ( isset($attendance_record[$emp_key][$dates_value]['attendance']) ) {
$tabledata .= $attendance_record[$emp_key][$dates_value]['attendance'];
}
else
{
$tabledata .= "A";
}
}
$tabledata .= "\r\n";
}
$file_resource = fopen("att.txt","w+");
fwrite($file_resource,$tabledata);
mysql_close();
?>
preetg
Junior Poster in Training
95 posts since Jan 2010
Reputation Points: 11
Solved Threads: 4
hey.. you are genius.......... this prob solve........
i take date as a date Datatype and then dat run........ but coding part is done but the format for text file is not looking gud...........
dat is-
empcode/ename 2004-09-09 2004-08-14
but i want 1 2 3 like this .......... is it possible ?
preetg
Junior Poster in Training
95 posts since Jan 2010
Reputation Points: 11
Solved Threads: 4
i m using php 2.22 may be this function not supported by this version of php...................i used this function but with P or A it display P10 A10........
preetg
Junior Poster in Training
95 posts since Jan 2010
Reputation Points: 11
Solved Threads: 4
first study w3schools.com
preetg
Junior Poster in Training
95 posts since Jan 2010
Reputation Points: 11
Solved Threads: 4
date function is working properly now...........
preetg
Junior Poster in Training
95 posts since Jan 2010
Reputation Points: 11
Solved Threads: 4