Link to home
Start Free TrialLog in
Avatar of aej1973
aej1973

asked on

php /mysql count statement...

Hi, I have a column as shown below;

Chair_2014_03_03
;Chair_2014_03_05
Chair_2014_03_10
Footrest_2013_03_03
Footrest_2014_03_03
armchairs_2014_03_10
armchairs_2012_03_03
;armchairs_2013_03_03

I need to have a count of all chairs, footrest, and armchairs using php/mysql. I am not sure if there is a function in mysql that will give me the count with involving some php code. Can someone let me know how to do this?

Thank you,
A
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

If there is nothing else in that column, then COUNT(*) will work.  See here http://dev.mysql.com/doc/refman/5.1/en/counting-rows.html and here http://www.w3schools.com/sql/sql_func_count.asp
Avatar of aej1973
aej1973

ASKER

Hello Dave, I am familiar with the count statement, but I need to be able to strip the "," and "-201..." to be able to get the correct count.


A
ASKER CERTIFIED SOLUTION
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You may want to consider getting the assistance of a professional DBA to help you redesign this table.  You should be able to make queries like this very simply, but it looks like the data structure permits a collection of semi-useless data to invade the rows.

There are regular expressions that can help in the query, but for my money, a PHP script is the way to go.  Make a SELECT that captured all rows and look at each of them.  With a bit of PHP logic you can separate the fields into array collections of the data you want.  Then PHP count() will be your answer.
That should probably be an OR statement.
WHERE column LIKE '%Chair%' OR column LIKE '%Footrest%' OR column LIKE '%armchairs%'

Open in new window

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
While that is generally true... I wouldn't count on it.  And it is not true for database and table names using MyISAM engine on non-Windows systems because database and table names are also used for file names which are case-sensitive on those systems.  Someone noted recently that phpMyAdmin forces database and table names to be lower case at creation.  I think someone got tired of "answering the phone".
You're right -- case-insensitivity is not true for database and table names, just MySQL commands and the data that is housed in the database.  And like all things in computers, you can override the standard settings!  In my experience, unless you program it wrong, MySQL will honor the data, byte-by-byte, and will not make any alterations to case upon INSERT.  SELECT can control whether case matters, depending on initialization settings