PHP Classes

php array ordering

Recommend this page to a friend!

      Top level forums  >  PHP Specialists  >  General  >  php array ordering  
Subject:php array ordering
Summary:need to order an array by duplicate word then echo first 5
Messages:10
Author:Matthew Burns
Date:2009-11-25 00:05:10
Update:2009-11-26 08:34:08
 

  1. php array ordering   Reply   Report abuse  
Picture of Matthew Burns Matthew Burns - 2009-11-25 01:00:36
Hi I'm trying to order my tags my the number of time they occur and also limit the number of tags outputted (I only want 5).

Here is my script:
<?php
$sql="SELECT DISTINCT tags FROM stories";
$res=mysql_query($sql) or die($sql." - ".mysql_error());
if (!mysql_num_rows($res))
{
echo "";
}
else
{
while($row=mysql_fetch_array($res))
{
$string = $row[0];
$array = explode(',', $string);
foreach ($array as $value)
{
$bigarray[] = trim($value);
}
}
$bigarray = array_unique($bigarray);
foreach ($bigarray as $value)
{
If ($value=="")
{
}
else
{
echo "<a href=\"?mode=3&amp;tag=".ucfirst($value)."\">".ucfirst($value)."</a><br />";
}
}
?>

All my tags are in one col and delimited (eg. test, other, stuff)

is there a way to count how many of the same word are in the array and then echo the first 5 (the ones with the most duplicates)

Thanks

There are 9 replies in this thread, which are not being displayed.
Browsing this forum thread replies is available only to premium subscribers.


Go to the premium subscriptions page to learn how to become a premium subscriber and have full access to this forum.