Re: [PHP-DB] counting a value REVISED pt2
js wrote: p.s.- im using PHP with MySQL... if that helps any. thanks i want to know what i can use to count the number of times a value appears in a column listing where different values are listed. for example, say in the column of Favorite Number we have 100 students, and for each student his or her own row. and each student can pick a number from 1-10. So, we have a column of 100 rows and each field can contain either 1-10.Now, i want to know how can i count the number of times lets say the #2 appears in this list and give that count a number. so if #2 appears 43 times in that column, then i want it to say "2 is listed 43 times." how do i do this? thank you for your help with my beginner newbie questions. -james Did you really review your question much? Do you have a php script that has connected to the database already? -Robby -- Robby Russell, | Sr. Administrator / Lead Programmer Command Prompt, Inc. | http://www.commandprompt.com [EMAIL PROTECTED] | Telephone: (503) 222.2783 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] counting a value REVISED pt2
select count(FavNum) as Favorite where FavNum = 2; On Fri January 30 2004 8:19 pm, js wrote: > p.s.- im using PHP with MySQL... if that helps any. thanks > i want to know what i can use to count the number of times a value appears > in a column listing where different values are listed. for example, say in > the column of Favorite Number we have 100 students, and for each student > his or her own row. and each student can pick a number from 1-10. So, we > have a column of 100 rows and each field can contain either 1-10.Now, i > want to know how can i count the number of times lets say the #2 appears > in this list and give that count a number. so if #2 appears 43 times in > that column, then i want it to say "2 is listed 43 times." how do i do > this? thank you for your help with my beginner newbie questions. -james -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] counting a value
SELECT favourite_nb, COUNT(*) AS tally FROM mytable GROUP BY favourite_nb HTH Ignatius _ - Original Message - From: "js" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Friday, January 30, 2004 19:07 Subject: [PHP-DB] counting a value i want to know what i can use to count the number of times a value appears in a column listing where different values are listed. for example, say in the column of Favorite Number we have 100 students, and for each student his or her own row. and each student can pick a number from 1-10. So, we have a column of 100 rows and each field can contain either 1-10.Now, i want to know how can i count the number of times lets say the #2 appears in this list and give that count a number. so if #2 appears 43 times in that column, then i want it to say "2 is listed 43 times." how do i do this? thank you for your help with my beginner newbie questions. -james -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] counting a value
js typed this on 01/30/2004 10:07 AM: i want to know what i can use to count the number of times a value appears in a column listing where different values are listed. for example, say in the column of Favorite Number we have 100 students, and for each student his or her own row. and each student can pick a number from 1-10. So, we have a column of 100 rows and each field can contain either 1-10.Now, i want to know how can i count the number of times lets say the #2 appears in this list and give that count a number. so if #2 appears 43 times in that column, then i want it to say "2 is listed 43 times." how do i do this? thank you for your help with my beginner newbie questions. -james If your table was like this (in postgresql in this example): CREATE TABLE student_numbers ( id SERIAL, student_id int, fav_num int ); Now I have inserted in 9 rows of student id's and favorite numbers. # SELECT fav_num as "Favorite Number", count(*) FROM student_number GROUP BY fav_num; Favorite Number | count -+--- 1 | 1 2 | 3 3 | 1 5 | 3 7 | 1 Cheers, Robby Russell -- #--- # Robby Russell, | Sr. Administrator / Lead Programmer # Command Prompt, Inc. | http://www.commandprompt.com # [EMAIL PROTECTED] | Telephone: (503) 667.4564 #--- -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] counting a value
You have to be know SQL language to achieve this. I recommend you start getting familiar with this, it will open a whole world to you. Going by your example favorite having values 1-10: Table name: stats table fields: name, lastname,midinit,dob,country,state,address,favorite //backendfunction = odbc_exec( ), mysql_query( ), etc. $query = "Select count(favorite) from stats group by favorite" ; $result = backendfunction($myconn,$query); This will give you a result with all the totals that you can later access using the functions to cycle through result sets. Rock & Roll! - Original Message - From: "js" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Friday, January 30, 2004 12:07 PM Subject: [PHP-DB] counting a value i want to know what i can use to count the number of times a value appears in a column listing where different values are listed. for example, say in the column of Favorite Number we have 100 students, and for each student his or her own row. and each student can pick a number from 1-10. So, we have a column of 100 rows and each field can contain either 1-10.Now, i want to know how can i count the number of times lets say the #2 appears in this list and give that count a number. so if #2 appears 43 times in that column, then i want it to say "2 is listed 43 times." how do i do this? thank you for your help with my beginner newbie questions. -james -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php