Jump to content

Need help with counting records and creating an array


Jeffro

Recommended Posts

Alright.. I have enough trouble creating arrays but add in another layer and I really get confused.  Could someone help me figure this one out? 

 

Let's say I have a mysql db with a few hundred urls that all look like so:

 

http://atlanta.website1.com/topic1
http://atlanta.website1.com/topic2
http://atlanta.website2.com/topic1
http://florida.website1.com/topic1
http://florida.website1.com/topic2
http://florida.website1.com/topic3
http://florida.website1.com/topic4
http://florida.website2.com/topic1

 

Notice the state names are different and the websites. 

 

Now I want to:

1) Create the mysql query to do a total count on each state (regardless of website 1 or 2), so the result would lool like this:

atlanta (3)

florida (5)

 

 

2) Be able to create an array in my php code where I could at any time later in the page write a statement such as:

We show that florida has <? echo myflorida_count; ?> records.  

 

If anyone could shed some light, I would be eternally grateful.  :)

 

Thanks!

Link to comment
Share on other sites

Hi

 

Probably not efficient but this will do it:-

 

SELECT SUBSTR(someurl,8,INSTR(someurl,'.')-, COUNT(*)
FROM Places
GROUP BY SUBSTR(someurl,8,INSTR(someurl,'.')-

 

All the best

 

Keith

 

Worked beautifully to create the count.  Thank you, Keith!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.