Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- Oder of processing data
April 1, 2005, 7:52 am
rate this thread
On my site, i have a number of employees in the DB,
each of the employees can work together with max 3 colleagues.
The table 'employees'looks like the following:
'id' INT(5) , 'name' VARCHAR(50) , 'buddies_id' VARCHAR(20)
1 , John , '21-2-90'
2 , Bruce , '45-78'
First i run a query (LIMIT 20) to get 20 employees id's, names, and
'buddies'. The buddies are an array of max 3 id's of other colleagues.
I do a while $employees = $get_employees, print blah
I also store the values of buddies_id, turn that into a real array,
empty fields, duplicates, and sort the array.
Then i run a 2nd query, SELECT 'name' FROM employees WHERE id
This works fine, and thanks to someone else in this group, i managed to
the names in the returned buddies-id with ther id, so i can use
$returned_buddy; (and then i get the name belonging to id=4)
Well, what a story, and now the question: While i print out the names
in the first part, i need the names of their buddies together with
them. But since
i've done the printing already, i can't do it again.
How sould i do this?
I really hope this is clear, if not please ask.
Re: Oder of processing data
Bad idea. You need TWO tables:
id INT(5) employee INT(5)
name VARCHAR(50) buddy INT(5)
If you change your data design, here's an idea:
SELECT e1.name AS name,
e2.buddy AS buddyname
(employees AS e1 LEFT JOIN buddies ON e1.id buddies.empoyee)
LEFT JOIN employees AS e2 ON buddies.buddy = e2.id
ORDER BY e1.id;