Search the Community
Showing results for tags 'count'.
-
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!
- 11 replies
-
- php
- phpmyadmin
-
(and 3 more)
Tagged with:
-
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
- 1 reply
-
- mysql
- percentage
-
(and 1 more)
Tagged with:
-
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 replies
-
- php app
- calculations
-
(and 1 more)
Tagged with:
-
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
- 1 reply
-
- count
- multidimensio
-
(and 2 more)
Tagged with:
-
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);
-
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.
-
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>