Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Complicated Looping funciton!! Pls Help 1

Status
Not open for further replies.

Forri

Programmer
Joined
Oct 29, 2003
Messages
479
Location
MT
Hi All

Ok this will be very complicated to explain so bare with me ad if u eed any further info for helping me just ask!

Using: PHP and MySQL

Problem:

I have 2 tables Users and Users_Leave_Apps; Leave Applications are applied by each and every user but not everybody can approve the leave application...this was solved by adding a new field within the Users table called Reports_to which basically stores another User ID! Then when loading the approving section only those falling under your ID will appear. That worked fine as i only had to run a normal SQL query to retrieve the list.

Now the company structure has changed and My kind boss asked me to change the structure; meaning... he wants me to list all the Employees who Fall under Jack and if one of those has other employees who fall under him those are shown too! this can keep going on for ages.


eg:

Nick falls under Jack; and Jack falls under Joe;

If i'm Joe and i go under approve list i need to see all applications of Jack and Nick;

Whereas if i'm Jack i see only Nicks applications;


How can i create a function that will go thru the list and creating a list of users. I will then only have to go through the list of users and select their applications!

Any help would be greaty apprecited!

Thanks
Nick
 
What is your table structure ? Does it have a facility to identify who falls under whom ?

If yes,(lets say you are storing id (int) as a manger for employee) you can query the table something like
Code:
function getList($id) {
$sql = "SELECT * FROM <TABLENAME> WHERE manager = $id" ;
...
..get number of rows eg $numrows as well as the id of the retrieved employee eg $empid
echo $empname ; // display employee data

if ( $numrows > 0 ) getList($empid) ;// call the function itself
..

}

--------------------------------------------------------------------------
I never set a goal because u never know whats going to happen tommorow.
 
Thanks for your idea i will try it out:


This is my Users Table Structure

ID - Autonumber
Name
Surname
Reports_to - ID of the Manager (its the id from the same table)


Sorted out?

Thanks
Ncik

 
possibly a 'seniority' field required to make things really easy ;

1 = godmode, 1000=peasant.

Select * from table order by seniority;

that sound about right ? it should help to work out easily who is higher in the food chain than the next guy , ie you can only view stuff with seniority id less than (or equal to?) yours.

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Spookie...its seems to be working great! i will tell if it doesn't! hehe!


Tahnks
nick

 
If you need any other reading search on google for "parts explosion" this is a common problem to solve.
 

select a.mgrid, b.empid
from emp a, emp b
where a.mgrid = b.empid
connect by prior mgrid;

Oh, sorry, that's Oracle. ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top