473,396 Members | 2,036 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Oder of processing data

Hi Group,

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'
etc.
First i run a query (LIMIT 20) to get 20 employees id's, names, and
their
'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,
remove
empty fields, duplicates, and sort the array.
Then i run a 2nd query, SELECT 'name' FROM employees WHERE id
IN($array)

This works fine, and thanks to someone else in this group, i managed to
combine
the names in the returned buddies-id with ther id, so i can use
$returned_buddy[4]; (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.

Thanks.

Jul 17 '05 #1
3 1158
frizzle wrote:
Hi Group,

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'
etc.
<snip> i need the names of their buddies together with
them. But since
i've done the printing already, i can't do it again.


Normalize your data.

C.
Jul 17 '05 #2
i'm sorry?

Jul 17 '05 #3
NC
frizzle wrote:

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'
etc.
Bad idea. You need TWO tables:

employees buddies
id INT(5) employee INT(5)
name VARCHAR(50) buddy INT(5)
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?


If you change your data design, here's an idea:

SELECT e1.name AS name,
e2.buddy AS buddyname
FROM
(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;

Cheers,
NC

Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: André | last post by:
Hallo, erstmal vorweg: Ich bin noch ziemlicher Newbee also bitte nicht schlachten! Es geht darum den Inhalt eines bestimmten Verzeichnisses einer SIM-Karte zu interpretieren. Dazu hab ich den...
1
by: Ingo Kollesch | last post by:
Moin, gibt es eine DB2 Funktion/Abfrage oder View um die User/User Group abzufragen? Ich möchte in meiner Anwendung abfragen ob der eingeloggte User bestimmte Rechte auf der Datenbank hat. Kann...
2
by: Chris Cobb | last post by:
I have a table that currently contains 718000 rows. I wish to add a column to the table. Adding this column anywhere other than the end of the table requires exporting data, a drop and recreate,...
1
by: Daniel Walzenbach | last post by:
Hallo, ich bereite mich gerade auf die Prüfung 070-305 vor (langfristig MCSD) und suche noch Leute, die gerne mitlernen möchten. Ist einfach lustiger wenn mehrere Personen zusammenkommen....
1
by: Marvin Massih | last post by:
Hallo, ich möchte aus einem Webservice bzw. einer ASP.NET-Projekt einen Crystal-Report drucken. Ich brauche keinen Crystal-Viewer oder ähnlichen Käse. Doch bereits der Aufruf von ...
6
by: James Radke | last post by:
Hello, I have a multithreaded windows NT service application (vb.net 2003) that I am working on (my first one), which reads a message queue and creates multiple threads to perform the processing...
1
ADezii
by: ADezii | last post by:
Transaction Processing is a Database term that refers to the process of grouping changes to your data into a batch that is treated as a single, atomic unit. Either the entire batch of transactions...
0
ADezii
by: ADezii | last post by:
In the Tip of the Week #19, we demonstrated Transaction Processing, specifically as it applies to DAO (Data Access Objects). In this week's Tip, we'll illustrate how Transaction Processing can be...
0
by: tavares | last post by:
(Our apologies for cross-posting. We appreciate if you kindly distribute this information by your co- workers and colleagues.) ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.