|
|
| |
1. php array ordering |
|
Reply |
|
|
 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&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. |