hoopplaya4 Posted December 7, 2008 Share Posted December 7, 2008 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']; } } } Quote Link to comment Share on other sites More sharing options...
msinternet Posted December 7, 2008 Share Posted December 7, 2008 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 Quote Link to comment Share on other sites More sharing options...
hoopplaya4 Posted December 7, 2008 Author Share Posted December 7, 2008 Thanks msinternet. That helps, I see where you're going with that. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.