RE: [PHP-DB] Help with results output needed

From: Date: Wed, 11 Apr 2001 15:02:50 +0000
Subject: RE: [PHP-DB] Help with results output needed
Groups: php.db 
Request: Send a blank email to php-db+get-8489@lists.php.net to get a copy of this message
Hi Liz, thanks for the reply! I have tried this, as well as added to this approach, but I am still not sure what to do with the results of the query (count, sum(*)) to produce the needed final output ("5 chose A for answer1", or "20% chose A for answer1"). Using the code below with my additions quickly added up. Something like 16 lines just for answer1 :( $result1A=mysql_query("SELECT answer1 FROM $table_name WHERE answer1 LIKE 'A'"); $row1A=mysql_num_rows($result1A); print $row1A; $result1B=mysql_query("SELECT answer1 FROM $table_name WHERE answer1 LIKE 'B'"); $row1B=mysql_num_rows($result1B); print $row1B; etc. etc. I am getting '0' or '1' back from the db as my output, I think I need to somehow get this into an array, or ? then perhaps add a while {} loop but I am still quite lost :( Thanks again, Phil -----Original Message----- From: Liz Bander [mailto:lbander@cisco.com] Sent: Wednesday, April 11, 2001 9:42 AM To: COMMONS, PHILIP Subject: Re: [PHP-DB] Help with results output needed I'm not sure if this will work (I'm pretty much new to this myself) but try something along the lines of the following (I have a similar query going in one of my scripts). $query = 'select answer1 from acct2301 where answer1 like 'A''; $results=mysql_num_rows($query); print $results; Liz (let me know if it works!) At 10:30 AM 4/11/2001, COMMONS, PHILIP wrote: >Hi, first post :) > >I have an interesting project. I have a basic form passing answers >into mysql. I have a db with multiple tables, each table contains >several fields, but I am only concerned with 16 of these fields >which contain the answers "A" "B" "C" "D" etc., not all >fields >contain the same number of answers (ie; some answers have A-G, >some only have A-D to choose from). My problem is extracting the >number of people that chose "A" for answer1, "B" for answer1, etc. > >Here is the layout: > >acct2301 (table) >answer1-answer16 are my fields > >username answer1 answer2 answer3 answer4 answer16 >---------------------------------------------------- >joeblow A F A E C >someguy A E B B C >joeuser B A E A D >someone D C D A A > >I have everything completed as far as getting the answers into the >tables,I just can't figure out the best way to extract the answers >and determine how many chose a given answer for each question. > >I have seen some examples using count(*), and (sum) I am thinking >I need to first determine how many A's, B's etc. then perform a >count on the result of that, but that is as far as I have been able >to get. > >Ideally a percentage function would be nice (20% chose A for Answer1, >etc.) > >Thanks for any help, I sure need it! > >-Phil

« previous php.db (#8489) next »