Page 1 of 1

Hierarchal Files System

Posted: Fri Aug 06, 2004 2:00 pm
by xjake88x
Hello, I'm working on a content management system called JakeSys (Click for demo). If you look at the files system, you can see that it's just post a file and it lists all the files along with a menu to rate them, download count, etc.

I want to make the system hierarchal but I have no idea how. For example, if I made a system to download web development tools. I could have sections like "Graphics", "PHP Scripts". And then in graphics I'd have "Free Templates", "Free Logos", and in php scripts I would have different categories of php scripts, and then in each category, I would have the actual scripts. I want to be able to add / delete / edit categories and files though.

My files table (js_files) has these values:
id (increasing int), name (text), description (text), downloads (int), author (text), poster (text), date (text), rating (int), rating_votes (int), url (text).

I don't know whether it will need multiple tables or what.

Thanks,

Posted: Fri Aug 06, 2004 2:05 pm
by feyd
generally, I'd go with a second table containing the hierarchy of "folders"... each one would have a parent_id field that points to their parent folder (unless it's a top level one)

each of the files would then have a field pointing to their containing "folder".

Posted: Fri Aug 06, 2004 2:43 pm
by xjake88x
Wow man.. This is actually working .. I'm proud of my self because on my first try for the new addfile.php (except for a forgotton semicolon), I got it so theres a list that is like:

/
/Code/
/Graphics/
/Code/PHP/
/Code/C++/
/Graphics/Templates/

Etc :D..

Posted: Fri Aug 06, 2004 2:46 pm
by feyd
coolness.. congrats.

Posted: Fri Aug 06, 2004 2:50 pm
by xjake88x
Had to do a while loop inside of a while loop :-P

Posted: Fri Aug 06, 2004 2:52 pm
by Joe
xjake88x wrote:Had to do a while loop inside of a while loop :-P
:O are you sure your not mistaken, lol

Posted: Fri Aug 06, 2004 3:14 pm
by xjake88x

Code: Select all

<select name="cat_id" id="cat_id">
          <option value="0" selected>/</option>
<?
$sql=mysql_query("SELECT * from js_filestruct");
while($r=mysql_fetch_array($sql)){
	$cat_pid=$r["parent_id"];
	$cat_path=$r["name"] . "/";
	while($cat_pid!=0){
		$sql2=mysql_query("SELECT * from js_filestruct where id='{$cat_pid}'");
		$r2=mysql_fetch_array($sql2);
		$cat_pid=$r2["parent_id"];
		$cat_path=$r2["name"] . "/" . $cat_path;
	}
	echo "<option value="" . $r["id"] . "">/" . $cat_path . "</option>\n";
}
?>

</select>
See!