On Tue, 2005-07-26 at 11:45 +0100, Shaw, Chris - Accenture wrote:
> 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)?
> 

I just need to find it's parent. This is part of a permission system i'm
building, and I need to somewhat register the objects in the permission
system so I can manage things easilly from there.

So to sum it up, this is my attempt to save queries :)

> What do you need to know?

Projects can only be parent or children. No more recursiveness than that
(it's possible, but we've implemented business rules that prevent it.)
What I'm trying to do is to add some sort of prefix to the fields
returned by the proj_parent table (wich is the projects table the same,
but with "different" info, and will overwrite the object's properties).

If not... heck, I'll have to make another query or use the associative
array sollution (wich neither will make me very happy, but that's life).

Thanks for your prompt reply :)

> 
> 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