there is a table prefix_wall

 ----------id 1 2 3 4 5 6 7 9 ----------wall_user_id 10 11 10 9 9 16 16 10 ----------user_id 12 22 33 32 33 44 22 434 

wall_user_id - id wall of the user user_id - id of the user who left the message

 вторая таблица 'prefix_user' ----------user_id 1 2 5 ----------user_profile_name Иванов Петров Саутин 

How to make such a conclusion so that it would output like this:

He took the wall_user_id and counted how many identical entries in it and displayed the number

 wall_user_id | кол-во записей которые повторяются 10 | 3 11 | 1 9 | 2 16 | 2 
 //ВЫВОД if(!isset($_GET['wall_user_id'])) { $result = mysql_query("SELECT wall_user_id, wall_user_id, COUNT( wall_user_id) AS wall_user_id FROM prefix_wall GROUP BY wall_user_id"); $myrow = mysql_fetch_array($result); do { echo "<b>".$myrow['wall_user_id']."-<br>" ; } while ($myrow = mysql_fetch_array($result)); } //ВЫВОД 
  • And COUNT canceled chtoli in mysql ? Have you tried to write something? - Alexey Shimansky
  • yes $ result = mysql_query ("SELECT wall_user_id, COUNT (*) FROM prefix_wall GROUP BY wall_user_id"); But he displays only 10 -11-9-16 and the number does not display them - ZOymyng
  • one
    it is not "it does not output a quantity", but you do not output this quantity, make count(*) as cnt and output the quantity in cnt just as you would print wall_user_id - BOPOH
  • so displays the count of SELECT wall_user_id, COUNT (wall_user_id) AS wall_user_id FROM prefix_wall GROUP BY wall_user_id "but without id, but how else to make the id and the count together was - ZOymyng
  • @ZOymyng, add your PHP code to the question body. - LEQADA

2 answers 2

Very simple. Comments, I think, are not needed

 SELECT wall_user_id, COUNT(wall_user_id) FROM prefix_wall GROUP BY wall_user_id 

UPDATE

(after editing the question)

In off. Documentation is an example regarding this point.

 $result = mysql_query("SELECT wall_user_id, COUNT(wall_user_id) FROM prefix_wall GROUP BY wall_user_id"); while ($row = mysql_fetch_array($result, MYSQL_NUM)) { printf("wall_user_id: %s Count: %s", $row[0], $row[1]); } 

And yes, use PDO. Your method is outdated and not secure.

  • After editing the TS question, your answer no longer makes sense. Alas. - Dmitriy Simushev
  • @DmitriySimushev, edited by. - LEQADA
  • ATP, it turned out. such a question, wall_user_id = id_user is the second table prefix_user where a id_user and name_user how to display instead of wall_user_id -> name_user Tell me - ZOymyng
  • I know that I need to use a JOIN, but for now I’m not going as well - ZOymyng
  • @ZOymyng, I recommend you read about SQL JOIN. Google: SQL JOIN examples. Or: SQL JOIN examples. - LEQADA

In general, here is the solution to the problem

 SELECT pu.user_profile_name, COUNT(pw.wall_user_id) as cnt FROM prefix_wall AS pw LEFT JOIN prefix_user AS pu ON (pu.user_id = pw.wall_user_id) GROUP BY pw.wall_user_id ORDER BY cnt DESC