Jump to content


Photo

Grouping / counting foreach results


  • Please log in to reply
1 reply to this topic

#1 jjfletch

jjfletch
  • Members
  • Pip
  • Newbie
  • 7 posts

Posted 04 April 2006 - 07:29 PM

The values of a field in my db looks like:

i.php, j.php, d.php?o=113, i.php, g.php, d.php?0=115, ...

So, the following foreach statement will basically pluck the elements that start with d.php and display them.

        preg_match_all('|d\.php\?.+?(?=,)|i', $row['longInfo'], $matchIt);
 
        foreach ($matchIt[0] as $sampX) { 
 
                echo "$sampX<br />";
 
        } 

The above foreach statement will generate the following:

// We'll call this part Main Blob 

d.php?o=113
d.php?o=113
d.php?o=113
d.php?o=113
d.php?o=115
d.php?o=115


What I actually need to display is:

d.php?o=113 = 4
d.php?o=115 = 2

Can someone show me how to do this? I tried nesting another foreach statement, but keep receiving "Wrong parameter count" errors.




#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,016 posts

Posted 04 April 2006 - 07:38 PM

array_count_values()

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users