Help a Girl ?? Get total of each in a table ?? Loop & Count ?

Hi Everyone and I just ran across this site a little while ago by simply googling = php help and pent now a couple of hours just reading some posts and following things… NICE!!

Amazing, and thank the site owner for having it. :smiley: and please be easy on me as I am also as I am not sure if I am even going to be using the right terminology what what I am trying to do.

I am new to php and mysql and really liking it and have gotten as far as being able to do the simple normal things like create the database and tables and then an entry form in which I now have have 516 records in.

Here is my table structure
[php]CREATE TABLE IF NOT EXISTS fab_centraldispatch (
id int(11) NOT NULL AUTO_INCREMENT,
date_time datetime DEFAULT NULL,
cd_type text,
cd_clientname varchar(255) DEFAULT NULL,
cd_clientcontact varchar(255) DEFAULT NULL,
cd_clientphone varchar(255) DEFAULT NULL,
cd_clientfax varchar(255) DEFAULT NULL,
cd_clientwebsite varchar(255) DEFAULT NULL,
cd_membersince varchar(255) DEFAULT NULL,
PRIMARY KEY (id),
KEY fb_order_cd_type_INDEX (cd_type(10))
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=516 ;[/php]

I have created scripts to Acess the database and can display all records, all of certain tables and the “total count” but where I am having a problem is that in my cd_type text, on the form I have a dropdown select with the following.

Doctor
Nurse
Nurses Aide

What I think?? I need to do is called loop thru this table and then somehow display the ‘count’ of each and print them out HTML? :-[

Like =

Total Doctors = 155
Total Nurses = 321
Total Nurses Aides = xxx

It’s just so easy to sort and look at once I export it into CSV, but learning to do this in php & mysql I am having fun, but getting ready to pull my haid out. :-\

Thanks ~!~!

Lisa

unfurtunately my phpmyadmin stopped working so i could not test your query

to fill a dropdown with database values

you echo the dropdown

like this

[php]
echo “”;
while($rows = mysql_fetch_array($nameofqueryResult))
{
echo “”.$row[‘example’]."";
}
echo “”;
[/php]

to get the account of a specific category you can runa query like this

[php]
//this will bring the total numbers of nurse in the database
$query = “SELECT COUNT(*) FROM table_name WHERE category = ‘nurse’”:
[/php]

[php]
//this will bring the total numbers of nurse in the database
$query = “SELECT COUNT(*) FROM table_name WHERE category = ‘nurse’”:
[/php]

Thank you sooooooo much for this reply, and then I just need to create an output statement and and a newline and repeat this with all 3 of them?

atually if you do it this way is better

[php]
$q1 = mysql_query(“SELECT * FROM table_name WHERE column_name=‘doctor’”);
//run the query and aisign the total rows to the variable
$numberResults_doctors = mysql_num_rows($q1);
[/php]
[php]
$q2 = mysql_query(“SELECT * FROM table_name WHERE column_name=‘nurse’”);
//run the query and aisign the total rows to the variable
$numberResults_nurse = mysql_num_rows($q2);
[/php]

to display the total ammount of record for instance doctor you just echo the variable

Sponsor our Newsletter | Privacy Policy | Terms of Service