PHP - Help With Category List Function
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. Similar TutorialsHi friends, I have two mysql db tables, photos and album, I would like to list photos by album how do i do that ? CREATE TABLE `album` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `album_name` varchar(95) NOT NULL, `album_desc` text NOT NULL, PRIMARY KEY (`id`) ); CREATE TABLE `photos` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `album_id` int(11) NOT NULL, `thumb_name` varchar(255) NOT NULL, `photo_name` varchar(250) NOT NULL, PRIMARY KEY (`id`) ) Hi Guys, I've been using PHP for a few years now but for some reason I can never seem to get my head around arrays, basically I have a blog site that I want to show all posts that have been posted in public categories but ignore those in the private categories, I had the idea to put all the private category ID's into an array and use that to check against the posts, however my array isn't working out the way I'd hoped. This is what I have: $isPrivate = mysql_query("SELECT categoryID FROM mod_cat WHERE isPrivate =1") or die (mysql_error()); while ($isPrivateList = mysql_fetch_array($isPrivate, MYSQL_NUM)) { $ignoreList = $isPrivateList; } However this isn't working at all. I know its wrong I just can't work out how to make it right. This is the mySQL I want to use it with: mysql_query("SELECT COUNT(*) AS total_entries FROM mod_posts WHERE articlePosted =1 AND articleCat != $ignorelist") Could anyone please help me? Thanks in advance. Hope someone here can help me. Ive been commissioned to convert a template to wordpress that includes a portfolio... I built a portfolio page from a custom post type. that works. Items are categorized with a custom taxonomy named port_cats. that works also On the portfolio page, there is tabbed content built with jquery to show and hide items by category. So theres a category nav menu, plus each item wrapped in classes to show and hide. Im stuck on plugging this in correctly, and am SO CLOSE. I have the category nav list working, but having trouble getting worpress to read the correct category slug inside the loop. Heres how the jquery needs to work: for the menu: Code: [Select] <li><a href="#" rel="category-slug">Category Name</a></li> to hide and show the items: Code: [Select] <ul> <li class="category-slug"> title/thumb/content </li> </ul> Heres my code: Code: [Select] <ul class="select"> <?php //list custom portfolio categories $taxonomy = 'port_cats'; // define portfolio categories from taxonomies in functions.php $tax_terms = get_terms($taxonomy); foreach ($tax_terms as $tax_term) { echo '<li><a href="#" rel="' . $tax_term->slug . '">' . $tax_term->name.'</a></li>'; } ?> </ul> <ul class="display"> <?php // ADD PORTFOLIO $loop = new WP_Query(array('post_type' => 'portfolio', 'posts_per_page' => 6)); while ( $loop->have_posts() ) : $loop->the_post(); $custom = get_post_custom($post->ID); $screenshot_url = $custom["screenshot_url"][0]; $website_url = $custom["website_url"][0]; ?> <li class="<?php echo $tax_term->slug; ?> "> <a href="<?=$website_url?>"><?php the_post_thumbnail(); ?></a> <?php the_title(); ?> <?php the_content(); ?> <a href="<?=$website_url?>Learn more</a> </li> <?php endwhile; ?> </ul> Whats happening is that worpdress is repeating the last category slug on every display item... can anyone tell me what i have wrong here??? THANK YOU! Trisha The web application should allow the user to view the items in a catalogue, add items to a shopping cart, remove items from the shopping cart, and to view the contents of the shopping cart. Hey guys. Right ill try explain as best i can. Basicly we were told to write a php script that can view a shopping cart. The items in the catalogue should be stored as an array of objects. (The next assignment will require you to store this list of objects in a database). There should also be pages to allow the user to add, edit and delete items in the catalogue. Thats taken from a brief.Ive spent the most of the week getting it to view a catalog and now it can add items.view the cart its added them to and remove them from the cart and return. What im having trouble with is making the add function for the the other users or admin* to add/edit/delete.i reckoned adding and deleting wouldnt be so bad considering ive alrready done so.But im kinda stumped on how to do it.i think what the brief wanted was a seprate product add that would actully let u add another product to the cart list on the same page and then u can add that to the shopping basket etc. Yea real stumped.if only it was through sql it would be so much handier. ill post the code below.if anyone can help at all in the slightest id be so grateful.Thank you. Since I'm new to programming I still don't know how to solve problems the most efficient way, I'd like to have your advice on this one. This is how I solved it and it works. I have my categories as input buttons (I'm planning to change it into a drop down menu later). Sort by Category: <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <input type='submit' name='All' value='All' /> <input type='submit' name='Smileys' value='Smileys' /> <input type='submit' name='Faces' value='Faces' /> <input type='submit' name='Love' value='Love' /> </form> When the input boxes are clicked the corresponding script below is being run, very simple and to a point primitive, definitely not really efficient, because if you have a lot of categories you'll end up with a lot of code and if you wanted to change one thing you'd have to change it in all the IF BLOCKS. Basically every input button has its own IF BLOCK. <?php if (isset($_POST['All']) OR (!isset($_POST['Smileys']) && !isset($_POST['Faces']) && !isset($_POST['Love']) { // Connect to the database $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); // Retrieve the score data from MySQL $query = "SELECT * FROM asciiart"; $data = mysqli_query($dbc, $query); // Loop through the array of score data, formatting it as HTML while ($row = mysqli_fetch_array($data)) { echo '<table class="asciiartTable">'; // Display the score data echo '<tr><td class="asciiart_name">'; echo '<strong>' . htmlentities($row['asciiart_name']) . '</strong><br /></td></tr>'; echo '<tr><td class="asciiart_contribution"><pre>' . htmlentities($row['asciiart_contribution']) . '</pre><br /></td></tr>'; echo '<tr><td class="asciiart_categoryDate">' . htmlentities($row['asciiart_category']) . ' | ' . date('M d, Y', strtotime ($row['created_date'])) . ' </td></tr>'; echo '</table>'; } mysqli_close($dbc); } if (isset($_POST['Smileys'])) { // Connect to the database $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); // Retrieve the chosen category from MySQL $query2 = "SELECT * FROM asciiart WHERE asciiart_category = 'Smileys'"; $data2 = mysqli_query($dbc, $query2); //Loop through the array of data while ($row2 = mysqli_fetch_array($data2)) { echo '<table class="asciiartTable">'; // Display the score data echo '<tr><td class="asciiart_name">'; echo '<strong>' . htmlentities($row2['asciiart_name']) . '</strong><br /></td></tr>'; echo '<tr><td class="asciiart_contribution"><pre>' . htmlentities($row2['asciiart_contribution']) . '</pre><br /></td></tr>'; echo '<tr><td class="asciiart_categoryDate">' . htmlentities($row2['asciiart_category']) . ' | ' . date('M d, Y', strtotime ($row2['created_date'])) . ' </td></tr>'; echo '</table>'; } mysqli_close($dbc); } if (isset($_POST['Faces'])) { // Connect to the database $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); // Retrieve the chosen category from MySQL $query3 = "SELECT * FROM asciiart WHERE asciiart_category = 'Faces'"; $data3 = mysqli_query($dbc, $query3); //Loop through the array of data while ($row3 = mysqli_fetch_array($data3)) { echo '<table class="asciiartTable">'; // Display the score data echo '<tr><td class="asciiart_name">'; echo '<strong>' . htmlentities($row3['asciiart_name']) . '</strong><br /></td></tr>'; echo '<tr><td class="asciiart_contribution"><pre>' . htmlentities($row3['asciiart_contribution']) . '</pre><br /></td></tr>'; echo '<tr><td class="asciiart_categoryDate">' . htmlentities($row3['asciiart_category']) . ' | ' . date('M d, Y', strtotime ($row3['created_date'])) . ' </td></tr>'; echo '</table>'; } mysqli_close($dbc); } if (isset($_POST['Love'])) { // Connect to the database $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); // Retrieve the chosen category from MySQL $query4 = "SELECT * FROM asciiart WHERE asciiart_category = 'Love'"; $data4 = mysqli_query($dbc, $query4); //Loop through the array of data while ($row4 = mysqli_fetch_array($data4)) { echo '<table class="asciiartTable">'; // Display the score data echo '<tr><td class="asciiart_name">'; echo '<strong>' . htmlentities($row4['asciiart_name']) . '</strong><br /></td></tr>'; echo '<tr><td class="asciiart_contribution"><pre>' . htmlentities($row4['asciiart_contribution']) . '</pre><br /></td></tr>'; echo '<tr><td class="asciiart_categoryDate">' . htmlentities($row4['asciiart_category']) . ' | ' . date('M d, Y', strtotime ($row4['created_date'])) . ' </td></tr>'; echo '</table>'; } mysqli_close($dbc); } My question is: is there a way to have just one block of script and the script automatically inserts the right INPUT BUTTON into the query in the script? Something similar to this, even though it doesn't work I'm just showing it for showcase purposes: if (isset($_POST['Smileys']) || (isset($_POST['Faces']) || (isset($_POST['Love'])) { // Connect to the database $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); // Retrieve the chosen category from MySQL $query2 = "SELECT * FROM asciiart WHERE asciiart_category = 'Smileys' || 'Faces' || 'Love'"; $data2 = mysqli_query($dbc, $query2); Notice in the query, it is looking for THAT keyword that has been PRESSED on the INPUT BUTTON. How would I be able to create a logic like this so I can create a whole chain of categories? Thanks for advice. 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 Hello, I have been developing a website that needs to display products online, I was originally going to hand-write the PHP code but I thought it would be more beneficial to make it database orientated as new products can easily be added and a search function becomes possible. I have it working so far so good, but the last part I can't seem to get working. I have it so all the products that have the desired category are displayed, but I want a more detailed analysis of the product to appear when the image is clicked, which at the moment, displays a blank page. http://www.webwib.co...?p=floorpuzzles - this is the hand coded version that demonstrates how I want it to work. http://www.webwib.co...hp?floorpuzzles - this is the db version so far, it works how it is intended to apart from the last stage, which returns as a blank page rather than a dedicated page for the selected product. Here is my code, the third segment beginning with "if(isset($_GET['$ID'])){", is my attempt at the final stage. <?php $db=mysql_connect ("localhost", "webwibco_charlie", "Hello123") or die ('I cannot connect to the database because: ' . mysql_error()); $mydb=mysql_select_db("webwibco_products"); include("header.php"); if(isset($_GET['floorpuzzles'])){ echo "<h1>Our Floor Puzzles</h1>"; $sql="SELECT ID, Name, Tags, Description, Category FROM products WHERE Category LIKE '%" . FloorPuzzles . "%'"; $result=mysql_query($sql); while($row=mysql_fetch_array($result)){ $Name =$row['Name']; $ID =$row['ID']; $Description =$row['Description']; echo "<div class=\"box\">"; echo "<h1>$Name</h1>"; echo "<div class=\"floorbox\"><a href=\"?$ID#productspage\"><img src=\"images/products/catalogue/$ID.jpg\" class=\"small\"></a></div>"; echo "<h2>$Description</h2>"; echo "</div>"; } } if(isset($_GET['anothercategory'])){ $sql="SELECT ID, Name, Tags, Description, Category FROM products WHERE Category LIKE '%" . AnotherCategory . "%'"; $result=mysql_query($sql); while($row=mysql_fetch_array($result)){ $Name =$row['Name']; $ID =$row['ID']; $Description =$row['Description']; echo "<h1>Our Floor Puzzles</h1>"; echo "<div class=\"box\">"; echo "<h1>$Name</h1>"; echo "<div class=\"floorbox\"><a href=\"?$ID0#productspage\"><img src=\"images/products/catalogue//$ID.jpg\" class=\"small\"></a></div>"; echo "<h2>$Description</h2>"; echo "</div>"; } } if(isset($_GET['$ID'])){ $sql="SELECT ID, Name, Tags, Description, Peices, Size, Barcode, Category FROM products WHERE ID LIKE '%" . $ID . "%'"; $result=mysql_query($sql); while($row=mysql_fetch_array($result)){ $Name =$row['Name']; $ID =$row['ID']; $Description =$row['Description']; $Pieces =$row['Pieces']; $Size =$row['Size']; $Barcode =$row['Barcode']; echo "<div class=\"1\">"; echo "<h1>$Name</h1>"; echo "<div class=\"bigbox\">"; echo "<div class=\"floorbox\"><img src=\"images/products/catalogue/$ID.jpg\" class=\"big\"></div>"; echo "</div>"; echo "</div>"; echo "<div class=\"2\">"; echo "<p>Puzzle Pieces: $Pieces</p> <p>Puzzle Size: $Size</p> <p>Barcode $Barcode</p>"; echo "</div>"; } } include("footer.php"); ?>Thank you in advance for any assistance given. 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 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... 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 Hey there, so as a personal project, I've been working on creating a forum software. You can check out what I have so far he https://www.taziamoma.com/Forum/index.php What I'm currently having trouble with right now is connecting a Category with a forum with the threads inside of it. For example, I have a Category that has 3 forums attached to it. How do I link that in the database and how do I indicate which threads belongs to which forums? I need some help with the category part on a old project . The problem what I have at this moment that, when I click on the category all categories are showing up on the category.php page itself. What whI wanne have when I click Uncategorised that in the category.php page only post are showing that have been made in Uncategorised category function get_posts() { $sql = "SELECT `blog`.`post_id` AS `id`, `blog`.`post_title` AS `title`, LEFT(`blog`.`post_body`, 512) AS `preview`, `blog`.`post_user` AS `user`, `blog_categories`.`id` AS `category_id`, `blog_categories`.`name` AS `category_name`, DATE_FORMAT(`blog`.`post_date`, '%d-%m-%Y %H:%i') AS `date`, `blog_comments`.`total_comments`, DATE_FORMAT(`blog_comments`.`last_comment`, '%d-%m-%Y %H:%i') AS `last_comment` FROM `blog` INNER JOIN `blog_categories` ON `blog_categories`.`id` = `blog`.`cat_id` LEFT JOIN ( SELECT `post_id`, COUNT(`comment_id`) AS `total_comments`, MAX(`comment_date`) AS `last_comment` FROM `blog_comments` GROUP BY `post_id` ) AS `blog_comments` ON `blog`.`post_id` = `blog_comments`.`post_id` ORDER BY `blog`.`post_date` DESC"; $posts = mysql_query($sql); $rows = array(); while (($row = mysql_fetch_assoc($posts)) !== false) { $rows[]= array( 'id' => $row['id'], 'title' => $row['title'], 'preview' => $row['preview'], 'user' => $row['user'], 'date' => $row['date'], 'category_id' => $row['category_id'], 'category_name' => $row['category_name'], 'total_comments' => ($row['total_comments'] === null) ? 0 : $row['total_comments'], 'last_comments' => ($row['last_comment'] === null) ? 'never' : $row['last_comment'] ); } return $rows; } function get_post($pid) { $pid = (int)$pid; $sql = "SELECT `post_title` AS `title`, `post_body` AS `body`, `post_user` AS `user`, `blog_categories`.`id` AS `category_id`, `blog_categories`.`name` AS `category_name`, DATE_FORMAT(`post_date`, '%d-%m-%Y %H:%i') AS `date` FROM `blog` INNER JOIN `blog_categories` ON `blog_categories`.`id` = `blog`.`cat_id` WHERE `post_id` = '$pid'"; $post = mysql_query($sql); $post = mysql_fetch_assoc($post); $post['blog_comments'] = get_comments($pid); return $post; }
The old way was like this if ( isset($cat_id)) { $cat_id = (int) $cat_id; $query .= " WHERE `blog_categories`.`id` = $cat_id"; } Database blog_categories id | name | ----------- 4 Uncategorised 1 Youtube blog post_id | cat_id | post_title | post_body | post_user | post_date ----------------------------------------------------------------------------------- 4 | 1 | Youtube | Youtube link | Admin | 2020-09-13 16:10:53 Web server Apache/2.2.21 (Win64) PHP/5.3.10 MySQL-client versie: mysqlnd 5.0.8-dev - 20102224 - $Revision: 321634 $ PHP uitbreiding: mysqli Documentatie phpMyAdmin Versie informatie: 3.4.10.1, meest recente versie: 5.0.2 I hope someone can help me with this problem 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? Hi all. This seems like a pretty basic function but I can't work it out. I'm developing a WordPress site and want to list posts (products) by category. I'm using Advanced Custom Fields and have set up the taxonomy of 'category'. I just want to produce a heading for that category and then list all of the posts with that category assigned. Please see below functions.php excerpt and section-archive.php excerpt. Can anyone please help??? Massive good karma if you can. ----------------------- functions.php -------------------------------------- //Assign Category to Products
function taxonomy ()
$args = array (
}; ?> ------------------------- section-archive.php ------------------------------------------------ <?php if(have_posts()):while(have_posts()): the_post();?>
****** if product category= this ***** Category heading ****** Posts ******* Else ****** if product category= this2 ***** Category heading ****** Posts **** etc
<div class="prod-listing">
Hello, I am trying create a news article, but I have few category in it. Can you help me to create an "add article form" which has dropdown list of category that I can choose, so when I select "Announcement" it will save the data on my mysql database under announcement table. sample html form below. <form id="form1" name="form1" method="post" action=""> <label> Category : <select name="category" id="category"> <option>--- choose category ---</option> <option>News</option> <option>Announcement</option> <option>Sports</option> </select> </label> <br /> Date: <br /> Title: <label> <input type="text" name="title" id="title" /> </label> <br /> Body: <label> <textarea name="body" id="body" cols="45" rows="5"></textarea> </label> <br /> <label> <input type="submit" name="Submit" id="Submit" value="Submit" /> </label> <br /> <br /> </form> Can you tell me how to create the php code which support the above html. Also, I would like to have a date and time on my article, but I want it automatically get the time and date from the computer of the client, so the user will not put it manually. can you point me to the correct code? Thanks and hope you can help me! 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! 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(); ?> |