PHP foreach() / PostgreSQL Brainiacs plz HELP

This is a discussion on PHP foreach() / PostgreSQL Brainiacs plz HELP within the PHP Language forums, part of the PHP Programming Forums category; I have a database full of names. each name could be linked to any number of sub-names, each sub-...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 09-09-2003
Peter
 
Posts: n/a
Default PHP foreach() / PostgreSQL Brainiacs plz HELP

I have a database full of names. each name could be linked to any
number of sub-names, each sub-name could be linked to any number of
sub-sub-names, to infinity (unlikely but possible).

I need to iterate through this nest of names starting with a main
name; lets call the main name Peter. Peter could have John, Tim & Mike
working for him. Tim could have Greg working for him.

function select_names($current_top_name){
global $dbh;

$sql = "
SELECT
name_id_fk
FROM
name_relation
WHERE
top_name_id_fk = '".$current_top_name."'
";
$rs = pg_query($dbh, $sql);

if(($num_rows = pg_num_rows($rs)) > 0){

for($i=0;$i<$num_rows;$i++){
$row = pg_fetch_row($rs, $i, PGSQL_ASSOC);
$associated_names[] = $row['name_id_fk'];
}

pg_free_result($rs);

} // end if(($num_rows = pg_num_rows($rs)) > 0)

return $associated_names;

} // end function select_names()

$current_top_name = 'Peter';

while(!$stop){

$assoc_names = select_names($current_top_name);

foreach($assoc_names as $key => $val){
print($val);
$more_assoc_names = select_names($val);
if($more_assoc_names){
ARG HELP IM NOT SMART ENOUGH
}

} // end while(!$stop)

} // end foreach($assoc_names as $key => $val)
Reply With Quote
  #2 (permalink)  
Old 09-09-2003
Jim Dabell
 
Posts: n/a
Default Re: PHP foreach() / PostgreSQL Brainiacs plz HELP

Peter wrote:

> I have a database full of names. each name could be linked to any
> number of sub-names, each sub-name could be linked to any number of
> sub-sub-names, to infinity (unlikely but possible).

[snip]

You have a tree. Check out the main link of this post, and the discussion
attached to it:

<URL:http://simon.incutio.com/archive/2003/06/19/storingTrees>

--
Jim Dabell

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 06:12 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0