This question has already been answered:

enter image description here

This code prints a list of all cells from the xfields field. Ie from the array key label

 Vision Vision Vision Sony Spinnin Spinnin ... 

And you need something like this.

 Vision - 3 треков Sony - 1 треков Spinnin - 2 треков ... 

In principle, it will do without a quantity, the main thing is that in one copy, but with a figure it would be better.

 <?php if (!defined('DATALIFEENGINE')) { die("Hacking attempt!"); } global $config; $limit = $limit ? intval($limit) : "20"; if (!$r_mlabel) { $sql = $db->query("SELECT * FROM " . PREFIX . "_post ORDER BY id DESC LIMIT 0,{$limit}"); while ($row = $db->get_row($sql)) { $xfieldsdata = xfieldsdataload($row['xfields']); $r_mlabel.= "<a href=\"/xfsearch/" . $xfieldsdata['label'] . "/\">{$xfieldsdata['label']}</a>"; } } echo $r_mlabel; ?> 

Reported as a duplicate by participants Mike , ermak0ff , vp_arth , Nicolas Chabanovsky Mar 7 '17 at 11:45 .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

  • you have already received 2 answers to this question here - ru.stackoverflow.com/questions/635680/… - n.osennij
  • Why duplicate? On the issue helped to withdraw, but on this need to group. - steep
  • You bring several varieties of the same problem. It is important to understand that if the problem is one, then the question should be one. Agree, if the two quadratic equations have different free terms, we will still use all the same formulas to find the roots. - Nicolas Chabanovsky

2 answers 2

Delete this question and return to the one that was asked 6 hours ago by this link.

Why do you duplicate questions? You have already received 2 answers to your question.

 $all=[]; while ($row = $db->get_row($sql)) { $arr=explode('|',$row['xfields']); foreach ($arr as $key => $value) { if (empty($value)) continue; if (array_key_exists($value, $all)) $all[$value]=$all[$value]+1; else $all[$value]=1; } } print_r($all); 
  • Questions are different, there to withdraw, and here to group and count. - steep
  • This is not done. You should supplement and correct your question. How to group and calculate, I have already answered you in that question. - n.osennij
  • Ну а дальше уже делаете с этим массивом что душе угодно, Перебираете, сравниваете, получаете по индексу. Счётчик увеличиваете свой, если нашли нужное. И т.д. This is not an answer. - steep
  • I brought the array and the key needed from it, now we need to group it somehow. - steep
  • Now we look at the code (in my answer above) and what I wrote to you in that question of yours. Then again on the code. Then again on what I wrote to you. And again on the code, and on what I wrote. All clear? - n.osennij

Fully working version

 if (!$r_mlabel) { $sql = $db->query("SELECT SUBSTRING_INDEX( SUBSTRING_INDEX( p.xfields, 'label|', -1 ) , '||', 1 ) as xf_label, count(*) as count FROM dle_post p WHERE LOCATE('label|',p.xfields)>0 GROUP BY xf_label ORDER BY count DESC LIMIT 0,{$limit} "); while ($row = $db->get_row($sql)) { $xfieldsdata = xfieldsdataload($row['xfields']); $r_mlabel.= "<a rel=\"ajaxlink\" class=\"mlabel\" href=\"/xfsearch/" . $row['xf_label'] . "/\">{$row['xf_label']}<span>{$row['count']}</span></a>"; } }