PHP - Creating A Category, Subcategory, Item Cms
Hello:
I would like to create a little CMS that will allow me to create a new Category (a State - one text field), then a Subcategory (A Town - one text field) that can be assigned to a State, and then a Menu Item (With a few text fields, a textarea, and a photo upload) that can be assigned to a Town. I have made these before with old ASP code but want to start develpoing this in PHP. I believe I found a demo of a Product Catalog online and worked from there. Can someone put me in the right direction? Or show me where I can fine a sample of this. I want to make it so it can be modified or deleted, if needed, but not to delete something if it's assigned to something (like not being able to delete a SubCategory if there are 3 Menu Items assigned to it). I would appreciate any help or direction. Thanks! Similar TutorialsI do have a sql table named "module" and a parent module may have a sub module. Each parent module can have a maximum of 9 sub modules of three per <td>. This is how this "module" table looks like: +-----------+------------------+----------+------+--------+---------------------+ | module_id | name | page_url | icon | parent | created_date | +-----------+------------------+----------+------+--------+---------------------+ | 1 | User Modules | | NULL | NULL | 2021-07-21 11:46:16 | | 2 | Items | | NULL | 1 | 2021-07-21 11:46:16 | | 3 | Add New Item | | NULL | 2 | 2021-07-21 11:46:16 | | 4 | View Item | | NULL | 2 | 2021-07-21 11:46:16 | | 5 | Category | | NULL | 2 | 2021-07-21 11:46:16 | | 6 | Brand | | NULL | 2 | 2021-07-21 11:46:16 | | 7 | Unit | | NULL | 2 | 2021-07-21 11:46:16 | | 8 | Purchase | | NULL | 1 | 2021-07-21 11:46:16 | | 9 | Add New Purchase | | NULL | 8 | 2021-07-21 11:46:16 | | 10 | view Purchase | | NULL | 8 | 2021-07-21 11:46:16 | | 11 | Due Invoice | | NULL | 8 | 2021-07-21 11:46:16 | | 12 | Return | | NULL | 8 | 2021-07-21 11:46:16 | | 13 | Purchase Log | | NULL | 8 | 2021-07-21 11:46:16 | | 14 | Inventory | | NULL | 1 | 2021-07-21 11:46:16 | | 15 | Stock Transfer | | NULL | 14 | 2021-07-21 11:46:16 | | 16 | Stock Adjustment | | NULL | 14 | 2021-07-21 11:46:16 | | 17 | Batch Control | | NULL | 14 | 2021-07-21 11:46:16 | | 18 | Stock Take | | NULL | 14 | 2021-07-21 11:46:16 | +-----------+------------------+----------+------+--------+---------------------+ My desired HTML table layout looks somthing similar to this attach image.
I would like to know how we can do it in php, if is possible. Thank you. Edited July 23 by thara Hi, I use this code (found in post http://www.phpfreaks.com/forums/index.php?topic=205633.0) to create a tree structure of categories and subgategories. Code: [Select] $prevcat = ''; $prevsubcat = ''; $sql = "SELECT * FROM $tbl_name ORDER BY categ, subcateg"; $result = mysql_query($sql) or trigger_error(mysql_error(),E_USER_ERROR); while($row = mysql_fetch_assoc($result)) { $cat = $row['categ']; $subcat = $row['subcateg']; $item = $row['itemname']; $description = $row['itemdesc']; if($cat != $prevcat){ echo $cat.'<br />'; echo 'sc '. $subcat.'<br />';//if the category has changed, we also want to show the new subcat }elseif($subcat != $prevsubcat){ echo $subcat.'<br />'; } echo 'it '.$item.'<br />'; echo 'desc '.$description.'<br />'; $prevcat = $cat; $prevsubcat = $subcat; } The above code works fine but I am trying to figure out how to count results of the deepest subcategory, so I will be able to change cell color or have results presented in two colums (left and right). Example: - main category 1 -- subcategory under category 1 ------ result 1 ------ result 2 ------ result 3 - main category 2 -- subcategory under category 2 ------ result 1 ------ result 2 - main category 3 -- subcategory under category 3 ------ result 1 ------ result 2 ------ result 3 ------ result 4 etc I want to count results under each subcategory, so on the above example I should have: 3 results for category 1 2 results for category 2 4 results for category 3 Any suggestions? Thank you. Hi there, I think this is a big question but I'd appretiate any help you can provide!! I have a list of items and subitems in a table that looks like this: id parent_id title 1 0 House Chores 2 1 Take Out Trash 3 1 Clean Room 4 0 Grocery List 5 4 Eggs 6 4 Produce 7 6 Lettuce 8 6 Tomato 9 4 Milk I want to display it like this: (+) House Chores: > Take Out Trash > Clean Room (+) Grocery List: > Eggs (+) Produce > Letutce > Tomato > Milk So basically each entry in the table has an unique id and also a parent id if it's nested inside another item. I "sort of" got it figured out in one way, but it doesnt really allow for nested subgroups. I'd like to know how would y'all PHP freaks to this Also taking suggestions for the javascript code to expand/collapse the tree !! Thank you! Hello, I have been searching and trying all sorts of ways to get my sub categories drop down to show the correct info after selecting a category from the main drop down but im getting stuck. It's pulling the categories and sub categories from the mysql database fine but no matter which main category i pick it keeps showing the same result in the sub category. My brother said i need to use some sort of onchange do this so the sub category list refreshs but everything i have tried doesn't work.. PLEASE could some one help. MANY MANY THANKS This is the category form Code: [Select] <select name="job_cats" style="width:165px"> <?PHP $query1 = "SELECT * FROM job_cats"; $result1 = mysql_query($query1) or die ("query 1 failed"); $count1 = mysql_num_rows($result1); for ($i = 0; $i < $count1; $i++) { $row1 = mysql_fetch_array($result1); $job_cats_title1 = $row1['title']; $job_cats_id1 = $row1['id']; echo '<option value="'.$job_cats_id1.'">'.$job_cats_title1.'</option>'; echo $job_cats_id1; } ?> </select> this would echo this in the main category list: cat1 cat2 cat3 cat4 this is the sub category form Code: [Select] <select name="job_sub_cats" style="width:165px"> <?PHP $query1 = "SELECT * FROM job_sub_cats WHERE job_cats_id = $job_cats_id1"; $result1 = mysql_query($query1) or die ("query 1 failed"); $count1 = mysql_num_rows($result1); for ($i = 0; $i < $count1; $i++) { $row1 = mysql_fetch_array($result1); $sub_cats_id1 = $row1['id']; $sub_cats_title1 = $row1['subTitle']; $cats_id1 = $row1['job_cats_id']; echo '<option value="'.$sub_cats_id1.'">'.$cats_id1.'</option>'; } ?> </select> this should echo this: 1 2 3 4 but it keeps echoing just the number 4. THANKS PLEASE HELP ricky I have a script that seems to work well to insert a bookmark into a users database when he/she is logged into the system but I am having a hard time figuring out how I would go about making a work-a-round for having an item selected before being logged in, and inserted after they have logged in or registered. For example, I would like a user to be able to select an Item to add to bookmark whether that user is logged in/registered or not and if they are not, they would be greeted with a login/registration form and after successful login the add bookmark script would be initiated on the item previously selected. What I've got this far: Simple form to add bookmark: <form name="bm_table" action="add_bms.php" method="post"> <input type="text" name="new_url" value="http://" /> <input type="submit" value="Add Bookmark"/> </form> Then I have the add bookmark script: BEGIN php $new_url = $_POST['new_url']; try { check_valid_user(); //cannot get past this part since it ends the script....code below if (!filled_out($_POST)) { throw new Exception('Form not completely filled out.'); } // check URL format if (strstr($new_url, 'http://') === false) { $new_url = 'http://'.$new_url; } // check URL is valid if (!(@fopen($new_url, 'r'))) { throw new Exception('Not a valid URL.'); } // try to add bm add_bm($new_url); echo 'Bookmark added.'; // get the bookmarks this user has saved if ($url_array = get_user_urls($_SESSION['valid_user'])) { display_user_urls($url_array); } } catch (Exception $e) { echo $e->getMessage(); } END php Checking valid user - the portion I cannot get past in the above script: function check_valid_user() { // see if somebody is logged in and notify them if not if (isset($_SESSION['valid_user'])) { echo "Logged in as ".$_SESSION['valid_user'].".<br />"; } else { // they are not logged in do_html_heading('Problem:'); echo 'You are not logged in.<br />'; do_html_url('login.php', 'Login'); do_html_footer(); exit; } } How would I go about modifying the script so that a user could fill in the form (later it would be a link...obviously they probably wouldn't be filling in a form that is log-in specific - but same concept I think) Thanks in advance for the help! tec4 Well I am looking to change this url Code: [Select] http://website.com/product.php?Item=2369 to Code: [Select] http://website.com/product.php?Item=Item-Name Heres a snip of the code that handles that. <?php include_once('mysql_connect.php');$id = (int)$_GET['Item'];?>() any help would be appreciated. I have the following result that I am getting from a source. Code: [Select] SimpleXMLElement Object ( [CategoryID] => 1 [Name] => Other [Order] => 0 [link] => http://www.link.com?sub=1 ) SimpleXMLElement Object ( [CategoryID] => 1233916011 [Name] => ceramic [Order] => 1 [ChildCategory] => SimpleXMLElement Object ( [CategoryID] => 1234016011 [Name] => dish [Order] => 1 ) [link] => http://www.link.com?sub=13476 ) SimpleXMLElement Object ( [CategoryID] => 1233917011 [Name] => laminate [Order] => 2 [link] => http://www.link.com?sub=98247 ) I need to get it into a database with the following structure Code: [Select] id categoryID cName cOrder clink cparent By using Code: [Select] foreach($this->resp->Store->CustomCategories->CustomCategory as $cat) { $sub = $cat->CategoryID; $ord = $cat->Order; $linkto = "$stlink?fsub=$fsub"; $nm = htmlspecialchars($cat->Name); $par=$cat->ChildCategory->Order; $query = "INSERT INTO Cat (categoryID,cName,cOrder,clink,cparent) VALUES ('$sub','$nm','$ord','$linkto','$par')"; $result = @mysql_query ($query); // Run the query. } I can get Code: [Select] id categoryID cName cOrder clink cparent 1 1 Other 0 http://www.link.com?sub=1 0 2 1233916011 ceramic 1 http://www.link.com?sub=13476 0 2 1233917011 laminate 2 http://www.link.com?sub=98247 0 But I need to get the ChildCategory in there w/ cparent like Code: [Select] id categoryID cName cOrder clink cparent 1 1 Other 0 http://www.link.com?sub=1 0 2 1233916011 ceramic 1 http://www.link.com?sub=13476 0 3 1234016011 dish 1 1 <--- like this 4 1233917011 laminate 2 http://www.link.com?sub=98247 0 any help appreciated... An array of "categories" is given: $categories = array( array("id" => 1, "title" => "Pants", "children" => array( array("id" => 2, "title" => "Boots", "children" => array( array("id" => 3, "title" => "Leather"), array("id" => 4, "title" => "Textile"), ), ), array("id" => 5, "title" => "Sneakers"), ), ), array( "id" => 6, "title" => "Sort", "children" => array( array( "id" => 7, "title" => "Balls", ), ), ), );
I need to write a function searchCategory ($categories, $id) that returns the name of the category by the category ID. So I am having some difficulties with a category system. I want my code to search the database an unlimited amount of times to the very last directory and then display it in tree view on my screen. I'm having some trouble because I am having to specify how many depths the code will search. How can I get it to do this on it's own? Currently my code does this... <?php // Establish SQL Connection. $mysqli = mysqli_connect( $sql['host'], $sql['user'], $sql['pass'], $sql['db'] ) or die( "DARN"); $query = $mysqli->query( "SELECT * FROM folders ORDER BY name ASC" ); $num_rows = $query->num_rows; echo "Found <b>" . $num_rows . "</b> row(s) in the database!<br>"; while ( $row = mysqli_fetch_array( $query ) ) { // DO NOT REMOVE $id = $row['id']; $name = $row['name']; $parent = $row['parent']; /***************************************************************************************************/ if ( $parent == 0 ) { echo $id . " " . $name . " " . $parent . "<br>"; $query2 = $mysqli->query( "SELECT * FROM folders WHERE parent = " . $id . " ORDER BY name ASC" ); while ( $row2 = mysqli_fetch_array( $query2 ) ) { echo " " . $row2['name'] . "<br>"; } } } ?>I know it's messy, doing the best I can. DB looks a little like this... +----+---------+--------+ Hope I am in the right area. I am working on a project which is sort of a business directory. I have a category table, a sub-category table then the actual account table. So a user clicks on the category, then selects the sub-category to view information of accounts in that category, and then be able to click to see the full profile. Here's where I am getting stuck. A user may be listed in more than one sub. As an example, let's say a parent is Cars, then subs might be New, Used, Parts, etc. Now a particular user might be listed under all three subs. How can I link them? I have my cat/sub linked via parent/child id's. However, how can I get the user to be linked to multiple subs? Would I need to create a separate table to do similar to parent/child of the categories? If so, then how would I insert the multiple id's into the table? I assume at this point that I would use drop downs for the subs. I am having a real hard time wrapping my head around this so any help is greatly appreciated. I have an image gallery with different categories, at the moment the list of categories is simple and just looks like this... General (10) I would like to be able to upload an image when making new categories and display it like this... Can anybody help me with this, here are the pages of code... This is the page that displays the category listing... Code: [Select] <?php include("config.inc.php"); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Roy Neale - Gallery</title> <link href="style/style.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="js/prototype.js"></script> <script type="text/javascript" src="js/scriptaculous.js?load=effects,builder"></script> <script type="text/javascript" src="js/lightbox.js"></script> <link rel="stylesheet" href="css/lightbox.css" type="text/css" media="screen" /> </head> <body> <div id="head"> <div id="headmain"> <div id="headleft"> <image src="images/bannertop.jpg"> </div> <div id="headright"> <div class="navimage"><image src="images/gallery3.png" onmouseover="this.src='images/gallery2.png'" onmouseout="this.src='images/gallery3.png'"></image><!--start navimage--> </div><!--end navimage--> <div class="navimage"><image src="images/about.png" onmouseover="this.src='images/about2.png'" onmouseout="this.src='images/about.png'"></image><!--start navimage--> </div><!--end navimage--> <div class="navimage"><image src="images/contact.png" onmouseover="this.src='images/contact2.png'" onmouseout="this.src='images/contact.png'"></image><!--start navimage--> </div><!--end navimage--> </div> </div> </div> <div id="mid"> <div id="midleft"> <p> </p> <p> </p> <p> </p> Login <p> </p> <p align="center"><form action="gallery.php" method="post" name="loginform"> <label>Username: </label><input name="username" type="text" class="userpass" size="25" maxlength="25" /> <label>Password: </label><input name="password" type="password" class="userpass" size="25" maxlength="25" /> <p><label></label><input name="submit" type="submit" class="logbutton" value="LOGIN" /></p> </form></p> </div> <div id="midright"> <div id="midrighttop5"> </div> <div id="midrightbottom4"> <?php // initialization $result_array = array(); $counter = 0; $cid = (int)($_GET['cid']); $pid = (int)($_GET['pid']); // Category Listing if( empty($cid) && empty($pid) ) { $number_of_categories_in_row = 3; $result = mysql_query( "SELECT c.category_id,c.category_name,COUNT(photo_id) FROM gallery_category as c LEFT JOIN gallery_photos as p ON p.photo_category = c.category_id GROUP BY c.category_id" ); while( $row = mysql_fetch_array( $result ) ) { $result_array[] = "<a href='gallery.php?cid=".$row[0]."'>".$row[1]."</a> "."(".$row[2].")"; } mysql_free_result( $result ); $result_final = "<tr>\n"; foreach($result_array as $category_link) { if($counter == $number_of_categories_in_row) { $counter = 1; $result_final .= "\n</tr>\n<tr>\n"; } else $counter++; $result_final .= "\t<td>".$category_link."</td>\n"; } if($counter) { if($number_of_categories_in_row-$counter) $result_final .= "\t<td colspan='".($number_of_categories_in_row-$counter)."'> </td>\n"; $result_final .= "</tr>"; } } // Thumbnail Listing else if( $cid && empty( $pid ) ) { $number_of_thumbs_in_row = '1'; $result = mysql_query( "SELECT photo_id,photo_caption,photo_filename FROM gallery_photos WHERE photo_category='".addslashes($cid)."'" ); $nr = mysql_num_rows( $result ); if( empty( $nr ) ) { $result_final = "\t<tr><td>No Gallery found</td></tr>\n"; } else { while( $row = mysql_fetch_array( $result ) ) { $result_array[] = "<a href='".$images_dir."/full_".$row[2]."' rel=\"lightbox\"><img src='".$images_dir."/tb_".$row[2]."' border='3' style='margin: 4px;' bordercolor='silver' alt='".$row[1]."' /></a>"; } mysql_free_result( $result ); $result_final = "<tr>\n"; foreach($result_array as $thumbnail_link) { if($counter == $number_of_thumbs_in_row) { $counter = 1; $result_final .= "\n</tr>\n<tr>\n"; } else $counter++; $result_final .= $thumbnail_link; } if($counter) { if($number_of_photos_in_row-$counter) $result_final .= "\t<td colspan='".($number_of_photos_in_row-$counter)."'> </td>\n"; $result_final .= "</tr>"; } } } // Full Size View of Photo else if( $pid ) { $result = mysql_query( "SELECT photo_caption,photo_filename FROM gallery_photos WHERE photo_id='".addslashes($pid)."'" ); list($photo_caption, $photo_filename) = mysql_fetch_array( $result ); $nr = mysql_num_rows( $result ); mysql_free_result( $result ); if( empty( $nr ) ) { $result_final = "\t<tr><td>No Photo found</td></tr>\n"; } else { $result = mysql_query( "SELECT category_name FROM gallery_category WHERE category_id='".addslashes($cid)."'" ); list($category_name) = mysql_fetch_array( $result ); mysql_free_result( $result ); $result_final .= "<tr>\n\t<td> <a href='gallery.php'>Categories</a> > <a href='gallery.php?cid=$cid'>$category_name</a></td>\n</tr>\n"; $result_final .= "<tr>\n\t<td align='center'> <br /> <img src='".$images_dir."/".$photo_filename."' border='0' alt='".$photo_caption."' /> <br /> $photo_caption </td> </tr>"; } } // Final Output echo <<<__HTML_END <table width='100%' border='0' align='left' style='margin: 6px;' style='padding: 5px;'> $result_final </table> </div> </div> </div> <div id="foot"> <div id="footmain"> <div id="footmainr"> <image src="images/copyright.png"> </div> </div> </div> </body> </html> __HTML_END; ?> And this is the page where i add new categories... Code: [Select] <?php include("config.inc.php"); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Roy Neale - Gallery</title> <link href="style/style.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="head"> <div id="headmain"> <div id="headleft"> <image src="images/bannertop.jpg"> </div> <div id="headright"> <div class="navimage"><a href="gallery.php"><img border="0" image src="images/gallery3.png" onmouseover="this.src='images/gallery2.png'" onmouseout="this.src='images/gallery3.png'"></image></a><!--start navimage--> </div><!--end navimage--> <div class="navimage"><image src="images/about.png" onmouseover="this.src='images/about2.png'" onmouseout="this.src='images/about.png'"></image><!--start navimage--> </div><!--end navimage--> <div class="navimage"><image src="images/contact.png" onmouseover="this.src='images/contact2.png'" onmouseout="this.src='images/contact.png'"></image><!--start navimage--> </div><!--end navimage--> </div> </div> </div> <div id="mid"> <div id="midleft"> </div> <div id="midright"> <div id="midrighttop3"> </div> <div id="midrightbottom2"> <?php if (isset($_POST['submit'])): $category_name = $_POST['category_name']; mysql_query( "INSERT INTO gallery_category(`category_name`) VALUES('".addslashes( $category_name )."' )" ); if (@mysql_query($sql)) { echo('<p>New category added</p>'); } else { echo('<p>New category added</p>'); } ?> <p><a href="<?=$_SERVER['PHP_SELF']?>">Add another category</a></p> <?php else: // Allow the user to enter a new category ?> <form action="<?=$_SERVER['PHP_SELF']?>" method="post"> <p><br /> New Category: <input type="text" name="category_name" size="20" maxlength="255" /><br /> <input type="submit" name="submit" value="SUBMIT" /></p> </form> <?php endif; ?> <p><a href="preupload2.php">Back to Upload</a></p> </div> </div> </div> <div id="foot"> <div id="footmain"> <div id="footmainr"> <image src="images/copyright.png"> </div> </div> </div> </body> </html> I assume i just need to edit a few mysql queries add another upload form and a few new fields or tables to my database, but i dont know how yet. I'm not sure why but I copied the correct syntax from the wp codex page for it to display the date and title which it displays the titles for the categories however it only displays the date for the headlines category and don't know why. Any answers? <?php get_header(); ?> <div id="left"> <div id="col1"> <img id="lp" src="../images/lp.jpg" alt="Latest Promo"> <img class="newslogos" src="../images/headlines.jpg" alt="DW Headlines"> <div class="mininews"> <?php //The Query query_posts('category_name=headlines'); //The Loop while (have_posts()) : the_post(); ?> <h3 class="date"><?php the_date(); ?></h3> <h4 class="title"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h4> <?php endwhile; //Reset Query wp_reset_query(); ?> </div> <!-- End of main news div (headlines) --> <img class="newslogos" src="../images/rumors.jpg" alt="DW Rumors"> <div class="mininews"> <?php //The Query query_posts('category_name=rumors'); //The Loop while (have_posts()) : the_post(); ?> <h3 class="date"><?php the_date(); ?></h3> <h4 class="title"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h4> <?php endwhile; //Reset Query wp_reset_query(); ?> </div> <!-- End of main news div (rumors) --> <img class="newslogos" src="../images/columns.jpg" alt="DW Columns"> <div class="mininews"> <?php //The Query query_posts('category_name=columns'); //The Loop while (have_posts()) : the_post(); ?> <h3 class="date"><?php the_date(); ?></h3> <h4 class="title"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h4> <?php endwhile; //Reset Query wp_reset_query(); ?> </div> <!-- End of main news div (columns) --> </div> <!-- End of col1 --> </div> <!-- End of left --> <div id="right"> </div> <?php get_footer(); ?> Hello everyone, I am currently working on the script taken from www.phpwebcommerce.com I am only a beginner and have been using it in a little project for an online game just to help my mates be able to trade items and such. I have managed to get almost everything sorted apart from one thing. The function which gets the categories for a drop down select box: Code: [Select] /* Generate combo box options containing the categories we have. if $catId is set then that category is selected */ function buildCategoryOptions($catId = 0) { $sql = "SELECT cat_id, cat_parent_id, cat_name FROM tbl_category ORDER BY cat_id"; $result = dbQuery($sql) or die('Cannot get Product. ' . mysql_error()); $categories = array(); while($row = dbFetchArray($result)) { list($id, $parentId, $name) = $row; if ($parentId == 0) { // we create a new array for each top level categories $categories[$id] = array('name' => $name, 'children' => array()); } else { // the child categories are put int the parent category's array $categories[$parentId]['children'][] = array('id' => $id, 'name' => $name); } } // build combo box options $list = ''; foreach ($categories as $key => $value) { $name = $value['name']; $children = $value['children']; $list .= "<optgroup label=\"$name\">"; foreach ($children as $child) { $list .= "<option value=\"{$child['id']}\""; if ($child['id'] == $catId) { $list.= " selected"; } $list .= ">{$child['name']}</option>\r\n"; } $list .= "</optgroup>"; } return $list; } Basically the problem is that it only creates a category list of two levels e.g. Parent Child and I wish to be able to have more sub categories e.g. Parent Child Child Child Is there anyway of adapting this code so it can do something like that? Many thanks for any help. I have created a form which allows people to add data to a database. However, I want to replicate the form across several pages and give each page a category. For example, if I have a website based on sport. I have a page which enters information into the baseball category, a page which enters information into the ice hockey category, a page which enters information into the soccer category etc. Can someone advise how I would do this? Hey i want to make category pages with php. so i have embeded youtube videos on my website and i want to make a category so that every embeded link that is named under that category goes on the new web page i am making. so lets say i have a category in my table that is called "Call of duty black ops" would the code be something like this ? ( and yes i want it to be ordered by date aswell ) Code: [Select] $query = "SELECT * FROM `G4V_Videos`.`Category`.`Call of duty black ops` ORDER BY `Date added` DESC LIMIT 24"; $result = mysql_query($query); thanks guys! Hi Guys (& Ladies of course) I'm having a problem trying to add post category to the H1 title, I have managed to butcher my theme so that the single post now removes the H1 from the title in the header & instead adds it to the post title. But what I'd like to do now is keep the H1 blog title on all pages including home page, but I'd like to ammend the title with the addition of the post category, as follows; currently shows "Top Rated Gadgets" on all pages. would like it to show "Top Rated (category name)" when viewing a single post. So if the category of the post was Asus Laptops it would show "Top Rated Asus Laptops" instead of the usual "Top Rated Gadgets" The closest I have got to it so far is with Code: [Select] <?php the_category(', '); ?> but this returns a hyperlink ! Is there any method I can use that will simply return the category name as plain text..? Any help would be much appreciated Thanks Hi, I have been working on a directory/cms script (first large script to build from scratch). I am stuck on a small part of it where is shows users a list of the listings they have put in the directory. Below is the code that generates the table that shows the list of listings which is pulled from the 'listings' table in my database. Code: [Select] <?php ### List of listings user has posted ### if(isset($_SESSION['userlogged'])) { $user_id = $_SESSION['userlogged']; $sqlCommand = "SELECT listing_id, cat_id, listing_title, listing_date, showing FROM listings WHERE showing='0' AND user_id='$user_id' ORDER BY listing_id ASC"; $query = mysql_query($sqlCommand,$con) or die (mysql_error()); $ListingDisplay = ''; while ($row = mysql_fetch_array($query)) { $listing_id = $row["listing_id"]; $cat_id = $row['cat_id']; if ($cat_id == '1') { $cat_name = "Carpenters"; } if ($cat_id == '2') { $cat_name = "Stone Masons"; } if ($cat_id == '3') { $cat_name = "Plumbers"; } if ($cat_id == '4') { $cat_name = "Landscapers"; } $listing_title = $row["listing_title"]; $listing_date = $row["listing_date"]; $ListingDisplay .= ' <tr class="listingaccount"> <td><a href="edit_listing.php?lid=' . $listing_id . '">' . $listing_id . '</a></td> <td>' . $cat_name . '</td> <td>' . $listing_title . '</td> <td>' . $listing_date . '</td> <td><a class="hoverBtn" href="edit_listing.php?lid=' . $listing_id . '"><img src="images/btnedit.png" border="0"></a></td> <td><a class="hoverBtn" href="remove_listing.php?lid=' . $listing_id . '"><img src="images/btndelete.png" border="0"></a></td> </tr>'; } mysql_free_result($query); ?> <table width="680" border="0" align="right" cellpadding="0" cellspacing="0"> <tr> <td colspan="2"><h2>My Listings</h2></td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td><a href="account_add_listing.php">Add New Listing</a></td> <td> </td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td colspan="2" valign="top"> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td>Listing Code</td> <td>Category</td> <td>Title</td> <td>Date Entered</td> <td> </td> </tr> <?php echo $ListingDisplay; ?> </table> </td> </tr> </table> <?php } ?> That all works just fine, but I would like to be able to generate the categories automatically. I am thinking some sort of array, but im not quite sure how to go about it and was hoping maybe someone could give me a starting point I could work from. My categories table is like this: -------------------------- | cat_id | cat_name | -------------------------- Many thanks Eoin hi i hv built a small posting system, i hv built few categories like this in mysql i hv these tables Categories table: id catname Post Table: id postbody posttile date catid so i am getting posts with catid for related posts like http://localhost/site/index.php?action=category&cat=1 so where $_GET['cat'] is 1 it display posts from that category 1, now what i need is when i post a new post i hv choice to assign multiple categories to one post, so a post could be in cat1 and in cat2 as well . please any idea how can i do that? i was thinking to make a new rows in posts table for each category and set it to 0 or 1 , and when i submit new post it will set 1 to those categories which i select upon writing post. but if i have like 20 categories i need to add more 20 rows in posts table. is there any other better way i can accomplish this? Thanks for help Hi How can i see which category is being used in rss feed, this is my code to parse one rss feed. $feed_url = "http://www.foo.com/feed/"; $xml = simplexml_load_file($feed_url); foreach ($xml->channel->item as $item) { $ns_content = $item->children('http://purl.org/rss/1.0/modules/content/'); $title = $item->title; // This is title $desc = $ns_content->encoded; // This is description $category =""; // Here i am stuck, how can i get category associated with this feed } How can i see its category, i see in source code it looks like this and even categories have sub categories which looks same, i wants categories names to display wihich is associated with feed: <category><![CDATA[Health]]></category> <category><![CDATA[Men]]></category> thanks for any help. |