Hierarchal Files System

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
xjake88x
Forum Commoner
Posts: 50
Joined: Sun Aug 01, 2004 7:05 pm

Hierarchal Files System

Post 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,
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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".
User avatar
xjake88x
Forum Commoner
Posts: 50
Joined: Sun Aug 01, 2004 7:05 pm

Post 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..
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

coolness.. congrats.
User avatar
xjake88x
Forum Commoner
Posts: 50
Joined: Sun Aug 01, 2004 7:05 pm

Post by xjake88x »

Had to do a while loop inside of a while loop :-P
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post by Joe »

xjake88x wrote:Had to do a while loop inside of a while loop :-P
:O are you sure your not mistaken, lol
User avatar
xjake88x
Forum Commoner
Posts: 50
Joined: Sun Aug 01, 2004 7:05 pm

Post 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!
Post Reply