PHP leave tracking webpage
Moderator: General Moderators
Re: PHP leave tracking webpage
of course it wont work.. how the hell am i going to test without me having your database... you see I am not trying to solve your problem and I am just trying to help SOME parts of it... you can't just do a copy and paste, you need to OBSERVE how it was done and learn it and DO it yourself. Oh and we dont have all day to read your super long code and you need to make a simple way of presenting your problems.
Re: PHP leave tracking webpage
I dont understand you saying that you donot have access to my database when i have already provide the sample SQL file. I think you havent downloaded that attached timemate.zip. I do understand you are busy people. We all are!
Do let me know whether you want it uploaded on some free site supporting PHP, MYSQL.
I am not posting the whole code for only YOU to read and reply....i am posting for all....that's what a forum is all about...so that those people who are good at testing, debugging and locating errors will reply with the correct remedies....by no means have i said that i need you people to do my work. I am just asking for simple PHP solutions...haven't i said that i am new to PHP and need advice?
I cannot explain in general terms when the whole subject (PHP) is new to me...i would rather approach a problem specifically as i understand it and ask for advice from people who are willing to help a newbie rather than be rude and throw their weight around. There should be a willingness to help!
BTW, its not that i am not learning or researching.. mysql_result takes a "$result" array and not a "$query" array...i have modified the code snippet given by you and got around that mysql_result error (echoed results and checked), but now getting "No Query Output" though i am using the same query statement which works and draws data using my code...so dont know why its not displaying any data or atleast an error!
BTW, there was one person who got close to understanding my problem, if you care to check the earlier replies.
Please let me know in what form you want the sample database (.txt, .SQL etc), or if you want me to upload it on some site and provide you with the username and password.
Regards,
Do let me know whether you want it uploaded on some free site supporting PHP, MYSQL.
I am not posting the whole code for only YOU to read and reply....i am posting for all....that's what a forum is all about...so that those people who are good at testing, debugging and locating errors will reply with the correct remedies....by no means have i said that i need you people to do my work. I am just asking for simple PHP solutions...haven't i said that i am new to PHP and need advice?
I cannot explain in general terms when the whole subject (PHP) is new to me...i would rather approach a problem specifically as i understand it and ask for advice from people who are willing to help a newbie rather than be rude and throw their weight around. There should be a willingness to help!
BTW, its not that i am not learning or researching.. mysql_result takes a "$result" array and not a "$query" array...i have modified the code snippet given by you and got around that mysql_result error (echoed results and checked), but now getting "No Query Output" though i am using the same query statement which works and draws data using my code...so dont know why its not displaying any data or atleast an error!
BTW, there was one person who got close to understanding my problem, if you care to check the earlier replies.
Please let me know in what form you want the sample database (.txt, .SQL etc), or if you want me to upload it on some site and provide you with the username and password.
Regards,
Re: PHP leave tracking webpage
no, you said you want the queried datas to be inserted in an ARRAY INSIDE an ARRAY, I gave you the code, and you just do simple modifications and your done.. What you did was COPY and PASTE and RUN and it DOESNT WORK so that's IT and you didn't even BOTHER correcting or modifying the code... get my point? And you know, that's your database and it is not mine, but the FOR LOOP for creating the array inside an array is working here.. but the QUERY, i just assumed it works, either way I just copied and pasted your query..
Re: PHP leave tracking webpage
If you see i have already modified the code and tested it.....heres a snippet....
Why dont you download the timemate.zip file, import the database tables using phpmyadmin etc. and put all the files in your root htdocs folder or WWW folder and see the output?
I am sure then we can be on same page....
regards,
Code: Select all
<?php
// Main Code starts here......
if($_POST)
{
$date1=$_POST['dateinputex1'];
$date2=$_POST['dateinputex2'];
// do the query...
$query="select em.code, em.firstname, em.lastname, ela.startdate, ela.enddate, ela.status from empmaster as em INNER JOIN empleaveapplication as ela ON em.employeeid=ela.employeeid where (ela.startdate>='".$date1."') and (ela.enddate<='".$date2."') and (em.departmentid=".$_POST['deptid'].") order by em.code ASC, ela.startdate ASC";
$result = mysql_query($query) or die("Query failed:".mysql_error());
// procceed only if there are queried results...
$num_rows = mysql_num_rows($result);
if($num_rows>0)
{
// if there are results, then set up the mainarray where to store another set of arrays
$mainArray = array();
for($i=0; $i<$num_rows; $i++)
{
// set the queried attributes
$firstname = mysql_result($result,$i,"em.firstname");
$lastname = mysql_result($result,$i,"em.lastname");
$startdate = mysql_result($result,$i,"ela.startdate");
$enddate = mysql_result($result,$i,"ela.enddate");
$status = mysql_result($result,$i,"ela.status");
// from the queried attributes, we set the sub array
$subArray = array($firstname, $lastname, $startdate, $enddate, $status);
// then we insert insert into the main array the sub array
array_push($mainArray, $subArray);
}
/*Here Code for generating Table-Headers for days starting from StartDate and EndDate.*/
echo "<table border='1' cellspacing='0'>";
Why dont you download the timemate.zip file, import the database tables using phpmyadmin etc. and put all the files in your root htdocs folder or WWW folder and see the output?
I am sure then we can be on same page....
regards,
Re: PHP leave tracking webpage
and? did it work? do a simple echoing inside the if else statements to see if there really are queried values.. try echoing, the length of the array IF the values were really inserted into the array. and this is STILL a BIG QUESTION in your code.. where you have the "if($_POST)" <---- see? what the hell is that??
Re: PHP leave tracking webpage
ok. trying that now...
Do you mean echo the items of the $mainArray or $Result??
I tried replacing $result with $mainArray in
getting:
If i try replacing it back with $result,
No Errors, however, getting "No Query Output!" Though that same query works fine with my code (w/o the injected code).
Do you mean echo the items of the $mainArray or $Result??
I tried replacing $result with $mainArray in
Code: Select all
while($rec=mysql_fetch_array($mainArray))
{
Code: Select all
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\tst2.php on line 153
Code: Select all
while($rec=mysql_fetch_array($Result))
{
Re: PHP leave tracking webpage
you know why you're not getting an output?? i've modified your code
the query above works and it returns someting and the structuring of the array work... THE ERROR in your CODE is that on the parameters that is passed on your SQL statement such as the $date1 and $date2 is empty i guess...
Code: Select all
$date1 = "2008-08-20 00:00:00";
$date2 = "2008-08-22 16:56:36";
$deptId = "1";
$query = "select em.code, em.firstname, em.lastname, ela.startdate, ela.enddate, ela.status from empmaster as em INNER JOIN empleaveapplication as ela ON em.employeeid=ela.employeeid where (ela.startdate>='".$date1."') and (ela.enddate<='".$date2."') and (em.departmentid=".$deptId.") order by em.code ASC, ela.startdate ASC";
$result = mysql_query($query) or die("Query failed:".mysql_error());
Re: PHP leave tracking webpage
No, i echoed the dates and the date variables contain the dates in Y-n-d format, though not in timestamp format...they seem to work in my previous code... also, if you see below...$mainArray, which is derived from $Result contains data, whereas $Result shows "Resource ID #4..
echoed $Result:
echoed $mainArray:
echoed $Result:
Code: Select all
Resource id #4
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\tst2.php on line 153
echoed $mainArray:
Code: Select all
Array ( [0] => Array ( [0] => zaki [1] => sheikh [2] => 2008-08-20 00:00:00 [3] => 2008-08-21 00:00:00 [4] => 1 ) [1] => Array ( [0] => zaki [1] => sheikh [2] => 2008-08-23 00:00:00 [3] => 2008-08-25 00:00:00 [4] => 3 ) [2] => Array ( [0] => zaki [1] => sheikh [2] => 2008-08-29 00:00:00 [3] => 2008-08-30 00:00:00 [4] => 2 ) [3] => Array ( [0] => eijaz [1] => sheikh [2] => 2008-08-02 00:00:00 [3] => 2008-08-03 00:00:00 [4] => 1 ) [4] => Array ( [0] => eijaz [1] => sheikh [2] => 2008-08-05 16:55:46 [3] => 2008-08-08 16:55:51 [4] => 3 ) [5] => Array ( [0] => eijaz [1] => sheikh [2] => 2008-08-11 00:00:00 [3] => 2008-08-12 00:00:00 [4] => 1 ) )
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\tst2.php on line 153
Re: PHP leave tracking webpage
good.. you cannot just directly echo the $result.. hey it worked?.. so there you have it.. as i can see from the main array, the main array contains all the queried result now..
Re: PHP leave tracking webpage
No, i am using print_r to display array values and keys...Also echoed $firstname etc and they show the values...but below when it comes to mysql_fetch_array, it gives that error...
BTW, have you downloaded and seen the database and the php webpage???
BTW, have you downloaded and seen the database and the php webpage???
Re: PHP leave tracking webpage
how the hell did you have a mysql_fetch_array? stick with the old loop that i gave you(for loop)..
"while($rec=mysql_fetch_array($mainArray))" <--- you used that?? you see $mainArray IS AN ARRAY, that's not a queried result from database.. you could've used "mysql_fetch_array($result)" because $result came from the MYSQL database.. $mainArray is not from the MYSQL DATABASE so it is not valid to use it for mysql_fetch_array() function..
"while($rec=mysql_fetch_array($mainArray))" <--- you used that?? you see $mainArray IS AN ARRAY, that's not a queried result from database.. you could've used "mysql_fetch_array($result)" because $result came from the MYSQL database.. $mainArray is not from the MYSQL DATABASE so it is not valid to use it for mysql_fetch_array() function..
Re: PHP leave tracking webpage
i have used mysql_fetch_array($result) but got "No Query Output!"... thats funny isnt it, when $mainArray is showing data taken from $Result?
Also, lets not deviate from the main problem i have on hand....if you have already downloaded my files and seen the php gantt page, you will see data being displayed like this (see attached):
for e.g. Employee "eijaz" is shown on 3 rows along with the corresponding colored leavedate ranges on the rows.
I want to show "eijaz" only once and on the same row show his colored leavedate ranges..
so eventually it should display employee names only ONCE and in their row display all the leavedates ranges as colored TD cells.
I am sure there has to be a way to compare employee name of 1st row with employee of all subsequent rows below and if TRUE, then echo Employee name once and display all his date ranges as colored TD cells in the same row...
See screenshot..
Also, lets not deviate from the main problem i have on hand....if you have already downloaded my files and seen the php gantt page, you will see data being displayed like this (see attached):
for e.g. Employee "eijaz" is shown on 3 rows along with the corresponding colored leavedate ranges on the rows.
I want to show "eijaz" only once and on the same row show his colored leavedate ranges..
so eventually it should display employee names only ONCE and in their row display all the leavedates ranges as colored TD cells.
I am sure there has to be a way to compare employee name of 1st row with employee of all subsequent rows below and if TRUE, then echo Employee name once and display all his date ranges as colored TD cells in the same row...
See screenshot..
- Attachments
-
- leavetracker.PNG (59.63 KiB) Viewed 1029 times
Re: PHP leave tracking webpage
ok that part is quite tricky.... well the solution i have is to re-organize your algorithm...
1] select all the employee ID only where all employees fall on that date range.. do a distinct on the query to eliminate the duplicates.
2] now that you have the employee ids, for each of the employee ids, get the date range of that employee.. note that the date range result will have more than one result.. and then for each of the date result of THAT empoyee id, display it on a table row... then move to the next employee id and do the same query and display again... so it's a loop..
3] I hope you got my point
1] select all the employee ID only where all employees fall on that date range.. do a distinct on the query to eliminate the duplicates.
2] now that you have the employee ids, for each of the employee ids, get the date range of that employee.. note that the date range result will have more than one result.. and then for each of the date result of THAT empoyee id, display it on a table row... then move to the next employee id and do the same query and display again... so it's a loop..
3] I hope you got my point
Re: PHP leave tracking webpage
Yeah, thats what i was trying to say all the time... 
1] Cannot use DISTINCT cos then it will only display one date range for each employee, isnt that correct? BTW, my query does the same what you say, i.e. narrow find employee dates within the given startdate and enddate...
but dont know how to write that kind of loop...
1] Cannot use DISTINCT cos then it will only display one date range for each employee, isnt that correct? BTW, my query does the same what you say, i.e. narrow find employee dates within the given startdate and enddate...
2] Its a some kinda loop. either the query may have to change or will have to incorporate some kind of loop in the while loop, for checking unique empcodes and then displaying all their dates in same row....Ok used DISTINCT but it shows the same duplicate records, one below the other
but dont know how to write that kind of loop...
Last edited by sifar786 on Mon Aug 25, 2008 5:47 am, edited 1 time in total.
Re: PHP leave tracking webpage
Code: Select all
$employeeIdResultQuery = mysql_query("SELECT DISTINCT FROM all the employees where the date range is specified");
if(mysql_num_rows($employeeIdResultQuery) > 0)
{
for($i=0; $i < mysql_num_rows($employeeIdResultQuery); $i++)
{
// get an employee id from the result query
$employeeId = mysql_result($employeeIdResultQuery,$i,"employee_id");
// then query the date range of that employee
$dateRangeResultQuery = mysql_query("SELECT ALL THE DATE of this employee WHERE employee_id='$employeeId') or die(mysql_error());
for($j=0; $j < mysql_num_rows($dateRangeResultQuery); $j++)
{
// for each of the date of the employee, arrange it in the table which i do not know how you will do it.
}
}
}