PHP - Count Of Categories And Subcategories Php Count
Anyone can help me?
<?php $tbl_name="menu"; $kategorije = mysql_query("SELECT * FROM $tbl_name WHERE Left(menu_name, 1) BETWEEN 'A' AND 'M' ORDER BY menu_name ASC"); if (!$kategorije) { die("Database query failed: " . mysql_error()); } while ($row=mysql_fetch_array( $kategorije )) { echo "<div id=lista-header><h4>{$row["menu_name"]}</h4></div>"; $id_sub=$row['id_menu']; $podkategorije = mysql_query("SELECT * FROM submenu WHERE id_menu=$id_sub ORDER BY sub_name ASC", $connection); if (!$podkategorije) { die("Database query failed: " . mysql_error()); } echo "<ul class=\"pod\">"; while ($pod=mysql_fetch_array( $podkategorije )) { echo "<li><a href=index.php?=podkate?".$pod["id_sub"]." class=black>{$pod["sub_name"]}</a><hr size=1 align=left width=100px color=#cccccc></li>"; } echo "</ul>"; } ?> In this way, I get list with categories and hes subcategories. How to count how many subcategories have each categories, and count how many articles have each categories? Example (I wanna get this kind of look): Categories name (3) subcategoriesname (2) subcategoriesname (4) subcategoriesname (7) Categories name (5) subcategoriesname (1) subcategoriesname (14) subcategoriesname (9) subcategoriesname (2) subcategoriesname ( Categories name (2) subcategoriesname (28) subcategoriesname (17) Where the numbers represent how many categories and sub-items have articles Similar TutorialsHi guys, I need your help. I am trying to insert the rows in the mysql database as I input the values in the url bar which it would be like this: Code: [Select] www.mysite.com/testupdate.php?user=tester&pass=test&user1=tester&email=me@shitmail.com&ip=myisp However i have got a error which i don't know how to fix it. Error: Column count doesn't match value count at row 1 <?php session_start(); define('DB_HOST', 'localhost'); define('DB_USER', 'mydbusername'); define('DB_PASSWORD', 'mydbpassword'); define('DB_DATABASE', 'mydbname'); $errmsg_arr = array(); $errflag = false; $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } function clean($var){ return mysql_real_escape_string(strip_tags($var)); } $username = clean($_GET['user']); $password = clean($_GET['pass']); $adduser = clean($_GET['user1']); $email = clean($_GET['email']); $IP = clean($_GET['ip']); if($username == '') { $errmsg_arr[] = 'username is missing'; $errflag = true; } if($password == '') { $errmsg_arr[] = 'PASSWORD is missing'; $errflag = true; } if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; echo implode('<br />',$errmsg_arr); } else { $sql = "INSERT INTO `members` (`username`,`email`,`IP`) VALUES ('$adduser','$email','$IP')"; if (!mysql_query($sql,$link)) { die('Error: ' . mysql_error()); } echo "The information have been updated."; } ?> Here's the name of the columns i have got in my database: Code: [Select] username IP I have input the correct columns names, so I can't correct the problem I am getting. Please can you help? This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=331562.0 Why am I getting this error when there are 3 Fields with 3 values? Column count doesn't match value count at row 1 Code: [Select] $sql5="INSERT INTO participants (participant_name, team_no, sport) VALUES ('".implode("','$_POST[team]'),('",$_POST['participant_name'])."','$_POST[team]','$sport')"; Hello,
New to php&mysql here and need a little help.
I want to make category list with sub-categories and sub-sub-categories. The goal is when I load website I will see full list with master(root)categories . Then when I click some categories should load sub-category and if I click on sub-category should load sub-sub-category. Something like this:
Computers -> Motherboards -> Model 1 -> Model 2 -> etc. Monitors -> Model 1 -> Model 2As you can see max level of sub-category will be 2+root. Here is the perfect example what I want to do http://3docean.net/category I don't understand(know) also how exactly will look my database table? How to store categories and sub-categories. I don't want someone to write full code etc as I want to learn it but will be great if you guys can show me some good tutorial how to make it mostly database structure. Thank you in advance! p.s. Sorry for my English! Hello, I am doing (well trying to do, anyway) a script where I need to follow a link, and through its source (file_get_contents) i need to to follow each "category" and into its "subcategory" (and sometimes even SUBsubcategory). Lets say the first in the menu is called "Catfood", the second "Dogfood", you click on "Catfood" and you get a submenu with for example "Whiskas", another one called "Purina Pro", and you click "Whiskas" and you see a list of food called for example "Whiskas Junior Chicken" and "Whiskas Junior Fish". then after i have followed "Whiskas", i need to go back and follow "Purina Pro". then after "Purina Pro" i need to go back to "Dogfood" and do the same to its submenu + subsubmenu + food menu.. so yeah, thats pretty much it basically.. i have already used wget for windows to download the entire website to not put load on it all the time when trying stuff out.. i use RegEx to find categories, their products and price, and i got all that covered, it's just that the website isn't built very friendly for using Regex to tie lets say "Purina Pro" with being in the "Catfood" category, so i have to go through all categories and subcats to save the categories in maybe an array, and bind the subcategories to the main category ("Purina Pro" with "Catfood") i hope this all doesn't sound too errr weird lol, any help is very much appreciated even enough to just get me started on my own! =) ****************** EDIT BELOW: The menu looks a bit like this, though it's orinally not about cat or dogfood, they are just examples Catfood - Whiskas - Purina Pro Dogfood - Royal Canin - Puppy food - Grown - Senior - Bozita Robur I have two tables subcat and category structure subcat id_subcat|id_of_cat|subcat_name| and for main categories ID_cat|cat_name| now what I want to display them as Main category subcategory1 subcategory2 Main category2 subcategoryX etc... Here's the code I'm using but doesn't work,it doesn't display anything. <?php $query = " SELECT ID_cat, id_subcat, subcat_name, cat_name FROM subcat, category WHERE ID_cat=id_subcat"; $result = mysql_query($sql); $lastCat = null; while($row = mysql_fetch_assoc($result)) { # Check if you need to print the category_name if($lastCat != $row['ID_cat']) { # Not the same category as the last one! # Print it and save the ID $lastCat = $row['ID_cat']; echo "<br />". $row['ID_cat']; } # Print the sub category echo "<br />". $row['subcat_name']; } ?> Hey all, If I want to have a category which can have subcategories, which in turn can have its own subcategories or belong to the parent category, and the subcategories can have more than one parent categories, is the most effective way to design this is to create a categories table and categories_join table where the categories table has a foreign key categories_join_id linking it to the categories_join table and the categories_join table has a field called parent_id which associates with the primary key of the categories table, therefore allowing me to have multiple subcategories to one category: categories_join table id parent_id 1 2 1 3 categories table id categories_join_id 1 1 2 2 3 3 So from the example above, the first category has two parents, category 2 and category 3. As an alternative option, in this post: http://stackoverflow.com/questions/5384183/database-design-question-categories-subcategories The second answer down mentions to use recursive programming? But he doesn't give an example of what he means. Is he saying you have a function call itself passing it parameters as to what the parent should be: function getParent($category,$parents = array()){ } Thanks for response. This topic has been moved to HTML Help. http://www.phpfreaks.com/forums/index.php?topic=327455.0 returns -30. how can i remove the minus so it just returns 30 Code: [Select] $days = (strtotime(date("Y-m-d")) - strtotime($info['expiredate'])) / (60 * 60 * 24) echo $days Hey All, I need to count and display the number of rows I have. <?php //declare the SQL statement that will query the database $query = " SELECT COUNT(id) FROM connectvisits WHERE staffid = '$staffid' "; //execute the SQL query and return records $result = mssql_query($query); $thismonth = mssql_num_rows($result); echo "Total Meetings This Month: "; echo $thismonth; echo "<br />"; ?> For some reason I keep getting a result of 1. Everything else I try gives me a "Resource ID" number. Any help would be apprecaited. Maybe I have the completely wrong code. Thanks! hey i'm just woundering how i would go abouts on echoing unread messages sent to a user i want to beable to see how many unread messages i have Hello,
I am trying to get the report of my sales table. I want to get total number of leads for each month. And then i have to use this data to create graph using google graph.
But i am not getting how eactly i can get this.
Here is my code
<?php if(isset($_POST['submit'])) { $type = $_POST['type']; $sql="select * from leads where lead_customer='".$type."'"; $query=mysql_query($sql); while ($row = mysql_fetch_array($query)) { list($year,$month,$day)=explode("-", $row['last_modified']); $l = $row['last_modified']; $count=mysql_num_rows($month); echo $count; $myurl[] = "['".$month."', ".$count."]"; } print_r($myurl); echo implode(",", $myurl); } ?>But for $count, it doesn't show any values. below is my database. Capture.PNG 18.16KB 0 downloads Please suggest me Hello, I'm using the following code to count the amount of SQL results and divide it. Works great as is but I want to alter it so it works with categories. $amount = mysql_query('SELECT COUNT(`car_id`) AS num FROM `tbl_cars`') or die(mysql_error()); $amount_row = mysql_fetch_assoc($amount); I tried adding... WHERE car_cat = '".$cat."' which causes an error. Why doesn't this work, and how can I get the amount of results as a variable? Hi, I want the user to be able to go to one page and hit a button, once he hits the butten I want a count down to start from 10 minutes. When the user goes to the page within those 10 minutes, I want it to show him a live countdown until those ten minutes run out. Any ideas how I would go about doing this? $count=0; $numb=50; foreach ($sepkeys as $dbkey) { for ($page=10;$page<=$numb;$page=$page + 10) { // the if block $count=$count+1; } } I am trying to maintain a separate a count for each key number in the above code. Eg: key- 574, it searches from pages 10-50 and increments the count by 1. The problem that I have is the count is continuous. After searching for the first key and moves on to the next key and them I need the count to start from the beginning rather than being continuous. Eg: key-874 : count = 22, in my case the next key 875 : the count is 23 I need to make it 1. I removed the if block and several lines because the code is too long. Can someone please suggest me a way how to do it I have this SQL query that gathers set information for the Salesperson($user) that is logged in and viewing theri need information. Everything works weell, except my Loop Count. I don't know, what I am doping incorrectly. It returns only two values which are the same. But the Query returns 10 values for that user. When I run the query direct in SQL DB. What am I missing? Code: [Select] <div class='page_content clearfix'> <div class='grid_8 first'> <?php $salesPersonId = & JFactory::getUser()->get('username'); //$merchantId = JFactory::getSession()->get('merchantId'); $db =& JFactory::getDBO(); $query = " SELECT XXX_merchant.*, XXX_merchant.name as MercName, XXX_merchant.address as MercAddress FROM XXX_sales_person, jXXX_merchant WHERE XXX_sales_person.user_name = '$salesPersonId' AND XXX_merchant.sales_person_id = XXX_sales_person.id"; $db->setQuery( $query ); $row = $db->loadObject(); //echo $query; //echo $query; //echo '<br>'; //echo $salesPerson->name; ?> <?php $link = 'index.php?option=XXX&controller=deal&task=view&id=' . $row->id; $count = 0; foreach ( $row as $row): $link = '/index.php?option=XXX&controller=merchant&task=edit&cid[]=' . $row->id; ?> <div class='quickie_login grid_9 last' style="width: 140px"> <div class='text_center' id='login_banner'> <div class='page_content text_center'> <div class="avatar" style="float: left; margin-top: -10px; padding: 0px;"> <a class="k2Avatar ubAvatar" href="<?php echo $link; ?>" title="<?php echo JText::_($row->MercName); ?> Edit Account" target="_blank"> <span class="ubName" style="display: block; margin-top: -20px;"><b><?php echo $row->MercName; ?></b> </span> <?php if(!empty($row->logo_url)) { $imagePathArr = unserialize(urldecode($row->logo_url)); $link='http://'; $link.= $_SERVER["SERVER_NAME"].$link_server.DS; $link.=$imagePathArr[0]; $link =str_replace("\\","/",$link); ?> <img src='<?php echo $link; ?>' alt="<?php echo $row->name; ?>" style="max-width: 100px; height:100px;"/> <?php } ?> </a> </div> <div class="sales-system2"> <div style="display: block; margin-top: 0px;"> </div> </div> </div> </div> <?php endforeach;?> I have the following array: Code: [Select] Array ( [item0] => Array ( [0] => name1 [1] => name2 [2] => name3 [3] => name4 [4] => name5 )etc... Is it possible to count the number of times a name exists in the compleet array? Thanx in advance! Can any one tell me whats the best ( actually error free ) which i can use to count the number of rows finally resulting after select command. I use this ... Code: [Select] $sql = mysql_query("select * from usname where name1='$name1' and name2='$name2' and amm='$amm'"); $num=mysql_num_rows($sql); echo $num; But it always gives the same error.... and the error is.......... Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\money\insert.php on line 20 where line 20 is... Code: [Select] $num=mysql_num_rows($sql); - Pranshu Agrawal pranshu.a.11@gmail.com I have an XML document that id decrypted and shown onto a table. At the bottom of the page, I'm trying to have it count up one Code: [Select] foreach($Data as $Types) // loop through book foreach($Types as $Colors) // loop through book { print_r(count($Colors->Color)); } There are 4 colors, blue, green, red, yellow. Blue is listed 7 times, green is 3, red is 8, and yellow is 4 times. What I expect it to print is: 7 3 8 4 Instead, it's printing this: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 If I was to just do the print function without count, it lists like this: blue red blue red green yellow blue red yellow red red green yellow yellow blue blue green blue yellow blue red red blue red My end-goal of this code is to get it to print this: Blue: 7 Green: 3 Red: 8 Yellow: 4 |