Jump to content

[SOLVED] Best way to create Folder Management


hoopplaya4

Recommended Posts

Hi All,

 

I've never done anything like this before using PHP and MySQL, so I'd very much appreciate if someone could point me in the right direction.

 

I currently have an area where admins can consistently post material into the database.  The admins also have the ability to add or create their own "folders" in the database, which helps to categorize the material they're uploading.

 

Right now, the current table structure I have is this:

 

CREATE TABLE `tblMaterials` (
  `materialID` int(11) NOT NULL auto_increment,
  `materialFile` varchar(30) default NULL,
  `materialFolder` varchar(30) default NULL,
  `materialTitle` text,
  `materialDescription` text,
  `materialCreate` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  `materialPostby` varchar(30) NOT NULL default '',
  PRIMARY KEY  (`materialID`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=36 ;

 

Now, I don't have any problems posting new material, but I'm not sure how to list all the "folders" and then display the "material" within the folder.  It's almost as if I need a "folderID" or something.

 

Here's what I currently have:

 

 <? 
  
      $sql = "SELECT DISTINCT materialFolder";
      $sql .= " FROM tblMaterials";
      $sql .= " ORDER BY materialFolder";

require("../connection.php");

$rs = mysql_db_query($DBname,$sql,$link);

if ($rs) {

   while ($row=mysql_fetch_array($rs)){
print ("<tr>\n");
print ("<td width='39px'><img src='../css/images/folder32.png' border='0'></td>\n");
print ("<td><h2><a href=material.php?action=viewMaterial&name='" . $row["materialFolder"] . "'>" . $row["materialFolder"] . "</a></h2></td>\n");
print ("</tr>");
  
     } //end While
 ?> </table> <?
}

}

function viewMaterial() {
  
$sql = "SELECT * FROM tblMaterials WHERE (materialFolder = " .  $_GET['name'] . ")";

require("../connection.php");

$rs = mysql_db_query($DBname,$sql,$link);

if ($rs) {

   while ($row=mysql_fetch_array($rs)){
  
     echo $row['materialID'];

  
  } 
  
  }
  
  }

Link to comment
Share on other sites

Hi,

 

<? 
  
      $sql = "SELECT DISTINCT materialFolder";
      $sql .= " FROM tblMaterials";
      $sql .= " ORDER BY materialFolder";

require("../connection.php");

$rs = mysql_db_query($DBname,$sql,$link);

if ($rs) {

   while ($row=mysql_fetch_array($rs)){
print ("<tr>\n");
print ("<td width='39px'><img src='../css/images/folder32.png' border='0'></td>\n");
print ("<td><h2><a href=material.php?action=viewMaterial&name='" . $row["materialFolder"] . "'>" . $row["materialFolder"] . "</a></h2></td>\n");
print ("</tr>");
// ADDITION HERE BY MS
  $extraquery = 'SELECT * FROM `tblMaterials` WHERE `materialFolder`= "' . $row['materialFolder'] . '";
  $extraresult  = mysql_query($extraquery);
  while($extrarow = mysql_fetch_assoc($extraresult)) {
    	print ("<tr class='fileRow'>\n");
print ("<td width='39px'><img src='../css/images/file.png' border='0'></td>\n");
print ("<td><h2><a href=material.php?action=viewFile&name='" . $row["materialFile"] . "'>" . $row["materialFile"] . "</a></h2></td>\n");
print ("</tr>");
  }


// ADDITION ENDS HERE  
     } //end While
?> </table> <?
}

}

function viewMaterial() {
  
$sql = "SELECT * FROM tblMaterials WHERE (materialFolder = " .  $_GET['name'] . ")";

require("../connection.php");

$rs = mysql_db_query($DBname,$sql,$link);

if ($rs) {

   while ($row=mysql_fetch_array($rs)){
  
     echo $row['materialID'];

  
  } 
  
  }
  
  }

 

Martin

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.