Php mysql count rows where condition
look at the database here ---->http://www.tiikoni.com/tis/view/?id=908d940 Show in the subcommentid rows, value 63 is repeating maximum time itself 7 times i want to fetch this value in numerical form means like this maximum rows in subcommentid is 7 i hv tried this
but but 63 is a variable so how can a server pre decide that 63 is repeating itself maximum nos nd look at dix ques too cant get my desire result of max(like)
asked Aug 19, 2014 at 7:55
6 use select count(*) from..... Or use mysql function mysql_num_rows($query_result). answered Aug 19, 2014 at 8:01
2 Try using this query -
If you want all, store in array -
answered Aug 19, 2014 at 8:33
TBITBI 2,7211 gold badge16 silver badges21 bronze badges 2
answered Aug 19, 2014 at 8:01
Use
Hope this helps you answered Aug 19, 2014 at 8:03
Utkarsh DixitUtkarsh Dixit 4,1973 gold badges14 silver badges36 bronze badges 2 COUNT() functionMySQL COUNT() function returns a count of a number of non-NULL values of a given expression. If it does not find any matching row, it returns 0. Syntax COUNT(expr); Where expr is an expression. MySQL Version: 5.6 Example : MySQL COUNT() function The following MySQL statement will return the number of rows in author table. Sample table: author Code:
Sample Output: mysql> SELECT COUNT(*) -> FROM author; +----------+ | COUNT(*) | +----------+ | 15 | +----------+ 1 row in set (0.00 sec) PHP script
View the example in browser JSP Script
Example : MySQL COUNT() with logical operator The following MySQL statement returns the number of publishers for USA and UK. The WHERE clause filters the rows for the country USA and UK. Grouping is performed on country and pub-city columns by GROUP BY and then COUNT() counts a number of publishers for each groups. Sample table: publisher Code:
Sample Output: mysql> SELECT country,pub_city,COUNT(*) -> FROM publisher -> WHERE country='USA' OR country='UK' GROUP BY country, pub_city; +---------+-----------+----------+ | country | pub_city | COUNT(*) | +---------+-----------+----------+ | UK | Cambridge | 1 | | UK | London | 1 | | USA | Houstan | 1 | | USA | New York | 2 | +---------+-----------+----------+ 4 rows in set (0.00 sec) Pictorial Presentation PHP script
View the example in browser MySQL COUNT() using multiple tables The following MySQL statement retrieves those rows from publisher table whose 'pub_id' in publisher table match the 'pub_id' in 'book_mast' table. A grouping operation is performed on pub_id column of publisher table by GROUP BY and then number of times pub_id exists in publisher table is counted by COUNT(). Sample table : book_mast Sample table: publisher Code:
Sample Output: mysql> SELECT publisher.pub_name,COUNT(*) -> FROM publisher,book_mast -> WHERE publisher.pub_id=book_mast.pub_id -> GROUP BY publisher.pub_id; +------------------------------+----------+ | pub_name | COUNT(*) | +------------------------------+----------+ | Jex Max Publication | 2 | | BPP Publication | 2 | | New Harrold Publication | 2 | | Ultra Press Inc. | 2 | | Mountain Publication | 2 | | Summer Night Publication | 2 | | Pieterson Grp. of Publishers | 2 | | Novel Publisher Ltd. | 2 | +------------------------------+----------+ 8 rows in set (0.00 sec) PHP script
View the example in browser Online Practice Editor: Previous: BIT_XOR() How do I count the number of rows in MySQL PHP?We can get the total number of rows in a table by using the MySQL mysqli_num_rows() function. Syntax: mysqli_num_rows( result ); The result is to specify the result set identifier returned by mysqli_query() function.
How do I count the number of rows returned by a query in MySQL?MySQL COUNT() Function
The COUNT() function returns the number of records returned by a select query.
How is it possible to know the number of rows returned in the result set in PHP?The mysqli_num_rows() function returns the number of rows in a result set.
How do I count the number of data in MySQL?How to use the COUNT function in MySQL. SELECT * FROM count_num; Run.. SELECT COUNT(*) FROM numbers; Run.. SELECT COUNT(*) FROM numbers. WHERE val = 5; Run.. SELECT COUNT(val) FROM numbers; Run.. SELECT COUNT(DISTINCT val) FROM numbers; Run.. |