I think the easiest way would be to use two arrays, one for counting, the
other for displaying
Advertising
-----Original Message-----
From: jtjohnston [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, March 05, 2002 10:48 AM
To: [EMAIL PROTECTED]
Subject: [PHP] Does anyone follow?
Does anyone follow what I'm trying to do?
I have a list of authors I explode from a field called AUS. I sort them
sort($authors);
The layout is agreeable. What I would like now to do is change:
array_push($authors,$singleauthor);
for
array_push($authors,$singleauthor,$mydata->id);
But how do I sort them now? These two lines permitted me to:
sort($authors);
foreach (array_count_values ($authors) as $author=>$count)
sort, count and display each occurence only once.
O'Henry, James (5) #<--- there were 5 occurences of O'Henry in my
database explode
Now what I want to do is display the id number (record number) of each
occurence of O'Henry:
O'Henry, James (5) [record 1, record 4, record, 87, record 119, record
120]
How do I re-evaluate this code, modify it to display authors one time
only,
count the number of occurences in my database
and somehow integrate $mydata->id ?
Does anyone follow what I'm trying to do?
------------------snip-----------------------------------
$myconnection = mysql_connect($server,$user,$pass);
mysql_select_db($db,$myconnection);
$news = mysql_query("select id,AUS from $table");
$authors = array();
while ($mydata = mysql_fetch_object($news))
{
$mydata->AUS = str_replace(" ;", ";", $mydata->AUS);
$mydata->AUS = str_replace("; ", ";", $mydata->AUS);
$tempauthors = explode(";", $mydata->AUS);
foreach ($tempauthors as $singleauthor)
{
if ($singleauthor <> "")
array_push($authors,$singleauthor);
}
}
sort($authors);
foreach (array_count_values ($authors) as $author=>$count)
{
echo "<a
href=\"match.php?searchenquiry=".urlencode($author)."&match=partial+match\">
".$author."</a>
(".$count.")<br>\n";
}
mysql_close($myconnection);
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php