Hello,

Consider this:
tbl_project(id, name, parent)

            1             6
           / \   / \
          2   3 7   8
         /\
        4  5

if tbl_project.parent = 0 then the project is the "top" parent.
Therefore, 1 and 6 have the field parent = 0.

So, say if you have project 5, do you want to find out its parent (2), or do
you want to find out all its parents including grandparents (2) and (1)?

What do you need to know?

C.
-----Original Message-----
From: André Medeiros [mailto:[EMAIL PROTECTED]
Sent: 26 July 2005 12:18
To: php-general@lists.php.net
Subject: [PHP] MySQL + PHP question


*************************************

This e-mail has been received by the Revenue Internet e-mail service.

*************************************

Hi guys.

I'm having some trouble here regarding a project. I have a table with
projects, wich can be recursive (ie. sub-projects) and it is related to
itself.

By making the following query

---------------------8<--------------------------
SELECT * FROM projects LEFT JOIN projects proj_parent ON
projects.project_parent = proj_parent.parent_id WHERE project_id = 1234
---------------------8<--------------------------

i need to be able to access to the parent project's fields, but I have a
slight problem here.

First off, I have to make the LEFT JOIN. I don't know if the project can
be parent (therefore not finding a project_id = 0 wouldn't show the row)
and I need to add some kind of prefix to the proj_parent's fields so
that I can access them (or that they can't overwrite the project i'm
getting info on.

Well... there is an obvious sollution here: use an associative array
instead of an object, and access the properties by doing $array[0],
$array[1], etc. By my experience, this is a nightmare, maintenence-wise,
so I'd only use it as a _LAST_ resource.

Does anyone have any experience with this? The answer should be pretty
obvious, but I can't seem to figure it out :(

Thanks in advance.

André

--

PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php





************************

This message has been delivered to the Internet by the Revenue Internet e-mail 
service

*************************

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to