Jump to content

Search the Community

Showing results for tags 'count'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

Found 21 results

  1. I'm really sorry for the poor explanation, I am absolutely not familiar with PHP. I would like to get data from my phpmyadmins 2 table, so I can display how many posts have been submitted with the same category type. One is called "posts" and the other one is called "categories". I have attached a picture to see the how it looks like. What I want is to make the category tables "id" equal to the posts tables "catagory_id", and then display how many posts have bben uploaded of each category. Here is how far I went with the coding, which is nowhere close to my expectations: <div class="stats__div"> <p class="stats__text">Categories</p> <p> <?php $all_categories_query = "SELECT * FROM categories ORDER BY title ASC"; $all_categories = mysqli_query($connection, $all_categories_query); while ($category = mysqli_fetch_assoc($all_categories)) : ?> <p><?= $category['title'] ?> <?= $category['id'] ?></p> <?php endwhile ?> <?php $all_posts_query = "SELECT * FROM posts GROUP BY category_id"; $all_posts = mysqli_query($connection, $all_posts_query); while ($posts = mysqli_fetch_assoc($all_posts)) : ?> <p><?= $posts['category_id'] ?></p> <?php endwhile ?> </p> </p> </div> I know, the coding is at the edge of being horrible, I am really sorry for that. I have tried my best. Does anyone know how to do that? I have seen that the right solution is using "array_count_values", but all the examples I have seen were lists. Any kind of help is highly appreciated!
  2. hi there, can i ask some help please. i need to get the addon percentage on my database... add on is being computed based on the difference between an invoice and estimate. my query goes like this: SELECT COUNT(estimate) as est, SUM(invoice-estimate) as addons, SUM(addons / est) * 100 as Percentage FROM tblestimates What is the best way to do this? i know that i cant use aliases on the computation i made. Thank you
  3. Hey I'm working on a simple program that will take user input from a HTTP form and use that to calculate a few things. I a few problems with my counter and I was wandering if anyone could point out something that could be causing my problem? Also if anyone know how to properly get a count on the positive even int's??? This is what I'm working with. $count = 0; $PosCount = 0; $uname = array($uname1, $uname2, $uname3, $uname4, $uname5, $uname6, $uname7, $uname8); for ($i; $i < count($uname); ++$i) { if ($uname[$i] == '0' || $uname[$i] == null) { //look to see weather its good or bad unset ($uname[$i]); //break that empty field $count = ($count - 1); } $count = $count + 1; if ($uname[$i] % 2 == 0 ) {//Even check $i = $uname[$i]; if ($i == round($i) || $i < 1) { //Pos Check $PosCount = $PosCount + 1; } } } than of course echoing all my desired values (sum, avg, max, min, and pos int count) - Thanks
  4. i HAVE FOLLOWING VALUES IN FEED TABLE a1a a1b a1c a1d ...... 7 8 7 7 8 9 8 8 9 7 7 8 7 8 10 9 6 4 6 7 7 8 8 5 9 7 7 6 This in an array ( select a1a,a1b,a1c,a1d from feed where .....) 1) I want to know how many times each values has occured in the array ( eg: 7 occured 10 times, 8 occured 8 times) 2) How many 7's, 8's, 9's are there in a1a, howmany .....in a1b Number of times each values occured OVERALL in array as well as also under each head Please help
  5. I get all the results displayed but how can I echo the total value for for all rows found for under column 'duration' which only contains numbers (seconds). $query = "SELECT * FROM asterisk_cdr WHERE calldate LIKE '%$calldate%' AND channel LIKE '%$channel%' AND duration"; $result = mysqli_query($dbcon, $query) or die('Error getting data'); $num_rows = mysqli_num_rows($result);
  6. My prof hasn't gotten back to me and he doesn't seem like even he knows how to do it so I'm posting here for some help. We've barely done any script writing yet and I can't seem to figure out how to go about doing it. He wants us to modify the existing script so that it generates a random number from 1 - 1000 and then counts the number of guesses and outputs how many guesses at the end. It won't open in the browser so I'm not sure what's wrong. Any help would be much appreciated! This is what I have so far: <?php if (!isset($_POST["guess"])) { $message = "Welcome to the guessing machine!"; $_POST["numtobeguessed"] = rand(1,1000); $_POST["counter"] = 0; } else if ($_POST["guess"] > $_POST["numtobeguessed"]) { $message = $_POST["guess"]." is too big! Try a smaller number."; $_POST["counter"]++; } else if ($_POST["guess"] < $_POST["numtobeguessed"]) { $message = $_POST["guess"]." is too small! Try a larger number."; $_POST["counter"]++; } else { // must be equivalent $message = "Well done! It took you '$_POST["counter"]' tries!"; } ?> <html> <head> <title>A PHP number guessing script</title> </head> <body> <h1><?php echo $message; ?></h1> <form action="" method="POST"> <p><strong>Type your guess here:</strong> <input type="text" name="guess"></p> <input type="hidden" name="numtobeguessed" value="<?php echo $_POST["numtobeguessed"]; ?>" ></p> <input type="hidden" name="counter" value="<?php echo $_POST["counter"]; ?>" <p><input type="submit" value="submit your guess"/></p> </form> </body> </html>
  7. I have a form on a page that has checkboxes for a number of entities, including one that is new. I want to determine how many checkboxes were checked for the new entity. The html is: <div id="new" style="display:block;">Which method(s) of valuation would you like to use for this report?<br /> <input type="checkbox" name="method_code['new'][]" value="EE">Excess Earnings<br /> <input type="checkbox" name="method_code['new'][]" value="DCF">Discounted Cash Flow</div> <div id="75" style="display:none;">Which method(s) of valuation would you like to use for this report?<br /><input type="checkbox" name="method_code['75'][]" value="EE" checked="checked" >Excess Earnings<br /> <input type="checkbox" name="method_code['75'][]" value="DCF" checked="checked" >Discounted Cash Flow</div><div id="79" style="display:none;">Which method(s) of valuation would you like to use for this report?<br /> <input type="checkbox" name="method_code['79'][]" value="EE">Excess Earnings<br /><input type="checkbox" name="method_code['79'][]" value="DCF">Discounted Cash Flow</div> <div id="77" style="display:none;">Which method(s) of valuation would you like to use for this report?<br /> <input type="checkbox" name="method_code['77'][]" value="EE">Excess Earnings<br /> <input type="checkbox" name="method_code['77'][]" value="DCF">Discounted Cash Flow</div> I looked for a method of counting the nuber of checked boxes for a given entity and found So, to count only non-empty: count(array_filter($array)); here and here So I implemented that in my code and it doesn't work. I put in the following to debug: echo '<pre>'; print_r($_POST['method_code']); echo '</pre>'; echo "arraycount ".count(array_filter($_POST['method_code']['new']));die(); and I get the following output: Array ( ['new'] => Array ( [0] => EE ) ['75'] => Array ( [0] => EE [1] => DCF ) ['78'] => Array ( [0] => EE ) ) arraycount 0 Why is the count 0? I expect that count(array_filter($_POST['method_code']['new'])) would be one since there is one element in that array.
  8. In this multi-table query, I gave each table a static value (e.g. 'GW' AS Site, 'GZ' AS Site)... $stm = $pdo->prepare("SELECT 'GW' AS Site, CGW.N, CGW.URL, CGW.Date, CGW.Year, CGW.Brief FROM calendar_gw CGW WHERE CGW.URL = :MyURL UNION ALL SELECT 'GZ' AS Site, CGZ.N, CGZ.URL, CGZ.Date, CGZ.Year, CGZ.Brief FROM calendar_gz CGZ WHERE CGZ.URL = :MyURL ORDER BY Year"); $stm->execute(array( 'MyURL'=>$MyURL ));
  9. Someone gave me a script that works - but it doesn't work for me. I've been trying to debug it, but I'm striking out. First, let's start with a simple query: $sql= "SELECT COUNT(URL) AS num FROM people WHERE URL = :MyURL"; It works, where a URL is MySite/Carl_Sagan and $MyURL = 'Carl_Sagan' I have several similar queries for various websites and sections. I want to try to merge everything into a new website that will function kind of like a mini encyclopedia. So I use UNION ALL to link several queries together, like this... $sql = "SELECT SUM(num) FROM ( SELECT COUNT(URL) AS num FROM pox_topics WHERE URL = :MyURL UNION ALL SELECT COUNT(URL) AS num FROM people WHERE URL = :MyURL UNION ALL SELECT COUNT(Taxon) AS num FROM gz_life WHERE Taxon = :MyURL ) AS X"; $stmt = $pdo->prepare($sql); $stmt->bindParam(':MyUrl',$MyURL,PDO::PARAM_STR); $stmt->execute(); $Total = $stmt->fetch(); switch($Total['num']) { case 1: // ETC.
  10. $query = "SELECT COUNT(*) as totalno FROM product GROUP BY prodCat ORDER BY prodName"; $result = mysql_query($query); while($data=mysql_fetch_array($result)) { $count = $data['totalno']; $query6="SELECT * FROM categories ORDER BY category"; $result6=mysql_query($query6); while($row6=mysql_fetch_array($result6)) { ?> <li> <?php echo $row6['category']; ?> (<strong><?php echo $count['prodID']; ?></strong>) </br> </br> </li> <?php $query="SELECT * FROM product where prodCat='".$row6['category']."' LIMIT 6"; $result=mysql_query($query); while($row=mysql_fetch_array($result)) { ?> <div id="product"> <a href="pDetails.php?id=<?php echo $row['id']; ?>"> <img src="data:image/jpeg;base64,<?php echo base64_encode($row["prodImage"]);?>" width="190px" height="190px" /> </a> <p> <b><?php echo $row["prodID"]; ?></b> </p> <p><?php echo $row["prodName"]; ?></p> <p>RM<?php echo $row["prodPrice"]; ?></p> <p> <a href="pDetails.php?id=<?php echo $row['id']; ?>" class="button">Product Details</a> </p> </div> <?php } } } ?> prodCat is product category.prodName is product Name. now my output is.. Category - product quantity --------------------------- Accessories - 4 Mouse - 4 Monitor - 4 CPU - 4 Bags - 4 this was wrong. I want the output is... Category - product quantity --------------------------- Accessories - 11 Mouse - 2 Monitor - 0 CPU - 5 Bags - 0 based on database to show the product quantity. How could i write the code.. please help. Thanks in advance Regards.
  11. Hi! I can't figure out this code: SELECT Student.fornavn,etternavn,brukernavn Fag.fagkode, COUNT(Oppgave.nr) AS AntalOppgaver FROM Student,Fag LEFT JOIN Student WHERE Fag.fagkode='DAT1000' = Syntax error , mariadb....... The task text is : The question should get an overview of all students(Here: Student) in a choosen subject(Here:fag) and count how many tasks(here:oppgave) The overview should show sirname(Etternavn)name(Fornavn) username(Brukernavn)and numbers of tasks in the subject(fag) The overview shuld be order by sirname(etternavn)and then on name(fornavn) Any idea? - Look at the E/R attachment
  12. hi, count number of words in textbox and then validate that the number of words should be between 400 to 1000. i googled alot... but didn't get an correct answer.... ??? need help!!! with regards, jasmeet.
  13. Hi, I am trying to build a table with counted results. My code works unless the count value is 0 (albeit there is likely a much cleaner way to do this and if you have time feel free to share your way) here is what I have: How do I get a count of 0 if the query returns no results? I should mention I get an empty table when the result is 0 <?php // Conection Info $con=mysqli_connect("localhost","*****","*****","*****"); // Check connection if (mysqli_connect_errno()) echo "Failed to connect to MySQL: " . mysqli_connect_error(); // Querys $c_nc_t1 = mysqli_query($con, " SELECT actcaseld, type, encdate, COUNT(type) AS c_nc_t1_type_count FROM `Stats` WHERE type='Type 1' AND actcaseld='New Client' AND encdate BETWEEN (SELECT bdate FROM `ReportRange` WHERE cf_id=1) AND (SELECT edate FROM `ReportRange` WHERE cf_id=1) GROUP BY type"); $c_nc_t2d = mysqli_query($con, " SELECT actcaseld, type, encdate, COUNT(type) AS c_nc_t2d_type_count FROM `Stats` WHERE type='Type 2 diet' AND actcaseld='New Client' AND encdate BETWEEN (SELECT bdate FROM `ReportRange` WHERE cf_id=1) AND (SELECT edate FROM `ReportRange` WHERE cf_id=1) GROUP BY type"); $c_nc_t2a = mysqli_query($con, " SELECT actcaseld, type, encdate, COUNT(type) AS c_nc_t2a_type_count FROM `Stats` WHERE type='Type 2 ADA' AND actcaseld='New Client' AND encdate BETWEEN (SELECT bdate FROM `ReportRange` WHERE cf_id=1) AND (SELECT edate FROM `ReportRange` WHERE cf_id=1) GROUP BY type"); $c_nc_t2ai = mysqli_query($con, " SELECT actcaseld, type, encdate, COUNT(type) AS c_nc_t2ai_type_count FROM `Stats` WHERE type='Type 2 ADA and Insulin' AND actcaseld='New Client' AND encdate BETWEEN (SELECT bdate FROM `ReportRange` WHERE cf_id=1) AND (SELECT edate FROM `ReportRange` WHERE cf_id=1) GROUP BY type"); $c_nc_t2i = mysqli_query($con, " SELECT actcaseld, type, encdate, COUNT(type) AS c_nc_t2i_type_count FROM `Stats` WHERE type='Type 2 Insulin' AND actcaseld='New Client' AND encdate BETWEEN (SELECT bdate FROM `ReportRange` WHERE cf_id=1) AND (SELECT edate FROM `ReportRange` WHERE cf_id=1) GROUP BY type"); // Output to html //Build Headers echo "<center><h3>Report for date range:</h3></center>"; echo "<table border='1' align='center'> <tr> <th></th> <th></th> <th>Type 1</th> <th>Type 2 Diet</th> <th>Type 2 ADA</th> <th>Type 2 ADA + Insulin</th> <th>Type 2 Insulin</th> </tr>"; //Build Data output to html while($row_c_nc_t1=mysqli_fetch_array($c_nc_t1) and $row_c_nc_t2d=mysqli_fetch_array($c_nc_t2d) and $row_c_nc_t2a=mysqli_fetch_array($c_nc_t2a) and $row_c_nc_t2ai=mysqli_fetch_array($c_nc_t2ai) and $row_c_nc_t2i=mysqli_fetch_array($c_nc_t2i)) { echo "<tr>"; echo "<td>Caseload</td><td>New Clients</td> <td><center>" . $row_c_nc_t1['c_nc_t1_type_count'] . "</center></td> <td><center>" . $row_c_nc_t2d['c_nc_t2d_type_count'] . "</center></td> <td><center>" . $row_c_nc_t2a['c_nc_t2a_type_count'] . "</center></td> <td><center>" . $row_c_nc_t2ai['c_nc_t2ai_type_count'] . "</center></td> <td><center>" . $row_c_nc_t2i['c_nc_t2i_type_count'] . "</center></td> "; echo "</tr>"; } echo "</table>"; // Close Connection mysqli_close($con); ?> Thank you in advance for your time and wisdom!
  14. Hi, usually I can search and learn and figure PHP out on my own (that's part of the fun of it for me), but this one is a little too big for me to wrap my head around this one. Okay here goes. I have a list of items in a textfile, each item on a separate line: apple orange orange grape lemon lemon lemon mango All I want to do is run a simple php script that will change that list to look like this: apple orange 2x grape lemon 3x mango I know some PHP genius will see this and be able to type the answer with one hand tied behind their back, while watching TV at the same time and talking on the phone to someone LOL. So, thank you, in advance, to that person! :-)
  15. I'm working on a site with a large category database > 3000 categories. I have successfully loaded my category list into phpmyadmin (tables in Myisam). However when attempting to load the site (localhost), the site times out. The site times out after 30seconds and gets stuck on a subcategory count in php. Here's the line of code it gets stuck at while loading: function GetSubCatCount($catid){ global $db, $the_cats; $count = 0; foreach($the_cats as $cat){ if(isset($cat->category_parent)){ if($cat->category_parent == $catid && $cat->category__auto_id <> 0 && $cat->category_lang == $dblang) { $count = $count + 1; } } } return $count; } This counting method seems rather slow. How can I speed up the count of the subcategories in php or have Mysql send the subcategory count values? Thanks and Regards! Database: pligg Table: pligg_categories Table details: |category__auto_id |category_lang |category_id |category_parent |category_name |category_safe_name |rgt |lft |category_enabled |category_order |category_desc |category_keywords |category_author_level |category_author_group |category_votes |category_karma Software version: 5.5.25a - MySQL Community Server (GPL)
  16. I created a function to count a number of appointments in my database: function bp_core_get_user_appointments( $user_id ) { global $wpdb; // Finds the total number of appointments a user has completed. if ( !$app_count_cached = wp_cache_get( '$app_count_cached_' . $user_id, 'bp') ) { $app_table = $wpdb->prefix . 'app_appointments'; $sql = $wpdb->prepare("SELECT COUNT(worker) FROM $app_table WHERE worker = $user_id AND status = 'completed' "); $app_count = $wpdb->query($sql); $app_count_cached = wp_cache_set( '$app_count_cached_' . $user_id, $app_count, 'bp', 86400); return $app_count; } else { $app_count = wp_cache_get( '$app_count_cached_' . $user_id, 'bp'); return $app_count; } } I then call this within another function thusly: $app_count = bp_core_get_user_appointments( $user_id ); if ( $app_count ) { $fullname .= ' [' . $app_count . ']'; } When I run the above SQL query in phpMyAdmin (modified slightly so it grabs the right table and everything), it produces the correct count. When it populates on my pages, however, it simply displays as: "[1]" This is regardless of how many actual appointments there are, so I'm guessing it's simply being pulled through somewhere as a boolean, i.e. "True - there are appointments here to count". But I'm not sure why. Where did I go wrong here?
  17. MYSQL version: 5.5.27-cll - MySQL Community Server (GPL) Hey I have a simple articles and comments table. I want to display the articles along with their comments. I want to union with one select with the comments and another select without the comments on the same table. I have article number 1 with 1 comment and article number 2 with no comments and article number 3 with 2. I use the following query to get the results. SELECT articles.id AS article_id, comments.id AS comment_id, comment FROM articles LEFT JOIN comments ON comments.aid = articles.id UNION ALL SELECT articles.id AS article_id, NULL, NULL FROM articles GROUP BY article_id ORDER BY article_id DESC The result I get which is correct: article_id | comment_id | comment 3 | 3 | good 3 | 2 | very good 3 | NULL | NULL 2 | NULL | NULL 2 | NULL | NULL 1 | NULL | NULL 1 | 1 | | bad one Now if I want to count the comments also I add COUNT to the query and it becomes: SELECT articles.id AS article_id, comments.id AS comment_id, comment , COUNT(DISTINCT comments.id) AS count_comments FROM articles LEFT JOIN comments ON comments.aid = articles.id UNION ALL SELECT articles.id AS article_id, NULL, NULL , NULL FROM articles GROUP BY article_id ORDER BY article_id DESC Now the results change after adding the the count column and not all rows are outputted: article_id | comment_id | comment 3 | NULL | NULL 2 | NULL | NULL 1 | NULL | NULL 1 | 1 | bad one Now the comments aren't displayed except the comment of article 1, ID(2) should be displayed twice for the 2 select commands, and ID(3) should be displayed 3 times (1 for the second select command and 2 for the first select commands as there are 2 comments) I don't know why adding count leads to ths. Thanks
  18. How to count time when it goes over the midniht ? For example lets say start time is 15:00 and end time is 01:00 then how to calculate time between there. I know one way is to add date to these times but is there a way around it ? I don't want to add 2 extra fields and force user to select dates.
  19. Hi everyone, I've been wrapping my head around this problem and I was wondering if you could help me. I have the following three tables with example data: results_patterns =========================== name | medal -------- | ------------ James | Gold James | Silver James | Silver Paul | Gold Sam | Bronze Sarah | Silver results_sparring =========================== name | medal -------- | ------------ James | Bronze James | Bronze James | Bronze Paul | Silver Sam | Gold Sarah | Silver results_patterns =========================== name | medal -------- | ------------ James | Silver James | Silver James | Gold Paul | Gold Sam | Bronze Sarah | Silver There are other columns in the tables such as date, age, category etc but these are not necessary. The idea being that there can be duplicate medals and names in each table (due to different competition dates) I'm trying to get a medal count for each individual person, and produce an sql statement to get a result like this: results =========================== name | gold | silver | bronze ---------|----------|-----------|----------- James | 2 | 4 | 3 Paul | 2 | 1 | 0 Sam | 1 | 0 | 2 Sarah | 0 | 3 | 0 I hope it's clear what I'm after; I'll happily explain more if required. I've tried UNION ALL three tables for WHERE 'Gold' medals. I wanted to count how many gold medals per person but I failed at this stage. I was then going to perhaps JOINT LEFT this results with the same for each Silver and Bronze. But I have no idea how to go about it. Any help would be greatly appreciated as I'm a noob with MySQL. Thanks very much
  20. Hi All, This code gives me the quantity output of the ordered products (per line): (int)($product['product_quantity']) Like: Product 1 - 5x Product 2 - 10x So, i want a function, that outputs the total of the order, like: Total products: 15x How can i store the code in an array and give the total order output? Thanks in advance! Bart
  21. Sorry I think my topic question is weird but just want to make the wordings as less as possible. I read a few of the threads but none of them seem to match what I need. What I'm trying to do it something like a voting system but does not include mysql at the moment. I made three radio buttons of music types pop, rock, metallic and a submit so whichever a person choose either one of them and submit the data is wrote into a data.json and stored there. Then I have a page to load all the data in data.json file but I want to count how many people selected for example metallic and how many people selected rock. at the moment I'm still testing and I actually thought of an idea but somehow searched up and not getting what I want.....can someone give me a hand? this is my data.json file {"type":"metallic"} {"type":"pop"} {"type":"metallic"} and this is what my result code is at the moment <?php $file = fopen('data.json', "r"); $array_record = array(); while(!feof($file)) { $line = fgets($file); $data = json_decode($line, TRUE); if (is_array($data)) { foreach ($data as $key => $value) { // echo $key.'='.$value.' '; // show key=value pairs $array_record += array($value,); var_dump($data); print_r($data); echo $value; } echo '<br>'.PHP_EOL; } } fclose($file); ?> I know the codes are messy because I tried setting up an empty array first then get the $value which is something like metallic into an array so I can use the array_count_values but the way I'm doing it seems totally wrong or that'd never work. I tried few other ways to get only metallic/pop so I can try counting the same thing. Thanks in advance.
×
×
  • 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.