I've got a table that contains file names and I've set up a query that generates an unordered list. The table has a record id (id) File Name and parentID. This all works perfectly.
Now I need to generate a serial number that reflects the position of the child in the table structure. Think if it as a file path. If documents was ID 4 and proposal was ID 9 and my-proposal was ID 15 Instead of documents/proposal/my-proposal I would to generate a serial number for myProposal like this: my-proposal SN 4.9.15 This shows me the lineage in the file tree and locates the document perfectly.
If my-proposal also had three children then they would show up in the directory structure like this:
documents/proposal/myproposal/
doc1(ID22)
doc2(ID23)
doc3(ID24)
If you're following me so far I have this code but it is giving me the children of the target and not the parents. IOW, I'm getting 22.23.24.15 instead of 5.9.15
PHP Code:
<?php // find Parents
$pgID = $row_pageRS['id']; // current record ID
$parent = $pgID; // assuming that pgID is the child
get_parents($parent);
function get_parents($parent) {
$sql = "SELECT * FROM files WHERE parentID = ".$parent."";
$run = mysql_query($sql);
while ($rec = mysql_fetch_assoc($run)) {
echo $rec['id'], '.';
get_parents($rec['id']);
}
mysql_free_result($rec);
}
echo $pgID;
?>
Any ideas would be appreciated. If I change bcID = to bcID < I get an endless string of 1's
** EDITED 4:25 Pacific Time ****
Just figured out part of the answer. The code above is working correctly. If you change the . in the HTML to <li /> and enclose the script in a <ul></ul> set you'll get a nice list of the files with indents. Changing the $parentID to 0 gives you the whole list so it makes sense that if I substitute the current page ID I'll get all of the children for that page.
Need another approach. I've been looking at a breadcrumb type of list generator to create my list. There's a start here:
http://911-need-code-help.blogspot.c...traversal.html
Haven't been able to adapt it yet. If you have any other ideas please let me know.