Re: Getting totals
| From: | Rafael | Date: | Thu, 08 Jun 2006 01:04:39 +0000 |
| Subject: | Re: Getting totals | ||
| References: | 1 2 3 4 5 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-237582@lists.php.net to get a copy of this message | ||
I really doubt you need to use strstr() here, since it will return a string (_if_ the 'needle' is found in the 'haystack')[1], I guess you're looking for strpos() or something similar.
Now, you said that you have this IPs on your database, so why don't you count the IPs directly on your database? If the examples you gave are real and the first 3 segments of each IP are the same, then you could group your records, clasify and count them. For example, if you were using MySQL, you can count them with something like
SELECT
SUBSTRING(ip, 1, 11) AS ip
COUNT(1) AS counter
FROM table
GROUP BY ip
ORDER BY ip ASC
*NOT tested
which should give you something like
ip | counter-------------+---------
192.168.100 | 1
192.168.101 | 2
··· | ···
192.168.110 | 11
[1] http://php.net/strstr
Rob W. wrote:
Sorry for the miss understanding, That's the way the viarable will look, i'm putting it in as a viariable. if (strstr($block,$address)) { $inc++; } ----- Original Message ----- From: "Richard Lynch" <ceo@l-i-e.com> To: "Rob W." <rob@fiberuplink.com> Sent: Tuesday, June 06, 2006 8:58 PM Subject: Re: [PHP] Getting totalsPut quotes or apostrophes on the strings... if (strstr('192.168.100','192.168.100.10')) { On Tue, June 6, 2006 8:46 pm, Rob W. wrote:if (strstr(192.168.100,192.168.100.10)) { $inc++; } echo "$inc"; That returns nothing. What am i still doing wrong? ----- Original Message ----- From: "Rabin Vincent" <rabin@rab.in> To: "Rob W." <rob@fiberuplink.com> Cc: <php-general@lists.php.net> Sent: Tuesday, June 06, 2006 1:36 PM Subject: Re: [PHP] Getting totalsOn 6/6/06, Rob W. <rob@fiberuplink.com> wrote:So far what I have gotten is a stristr match but it's not working correctly. I have a variable that basically weed's out the last digits of the ip it's self from help previously So my code so far is: if (stristr($block,$address)) { $count_ip++; }You've got the parameters mixed up. strstr is (haystack, needle) so you need strstr($address, $block). php.net/stristr. -- Atentamente / Sincerely, J. Rafael Salazar Magaña