RE: [PHP-DB] Re: Getting Percentage of coloumn value

From: Date: Wed, 10 Jul 2002 07:45:43 +0000
Subject: RE: [PHP-DB] Re: Getting Percentage of coloumn value
Groups: php.db 
Request: Send a blank email to php-db+get-20442@lists.php.net to get a copy of this message
<?php include "includes/required.php"; do_html_header('Name Here'); $query = "select count(id) as num_rows from tececo_stats"; $result = mysql_query($query) or die("Query failed: $query<br>" . mysql_error()); $row = mysql_fetch_array($result); $query = "select referer,(count(referer) / {$row['num_rows']} * 100) as total_in_percentage from tececo_stats group by referer"; $result = mysql_query($query) or die("Query failed: $query<br>" . mysql_error()); ?> <table width="500"> <?php while($row = mysql_fetch_array($result)) { echo "<tr><td>{$row['referer']}</td><td>{$row['total_in_percentage']}</td></tr>"; } ?> </table> <?php do_html_footer(); ?> Regards Joakim Andersson > -----Original Message----- > From: JJ Harrison [mailto:webmaster@tececo.com] > Sent: Wednesday, July 10, 2002 8:30 AM > To: php-db@lists.php.net > Subject: [PHP-DB] Re: Getting Percentage of coloumn value > > > Here is my script: > > <? > include "includes/required.php"; > do_html_header('Name Here'); > > $query = "select @total_items=count(id) from tececo_stats"; > $query1= "select referer,count(referer)/@total_items from > tececo_stats group > by referer"; > $result = mysql_query($query) or die("Query failed: $query<br>" . > mysql_error()); > $result1 = mysql_query($query1) or die("Query failed: $query1<br>" . > mysql_error()); > $num_results = mysql_num_rows($result); > ?> > <table width="500"> > <? > for ($i=0; $i < $num_results; $i++) > { > $row = mysql_fetch_array($result1); > echo > > '<tr><td>'.$row['referer'].'</td><td>'.$row['count(referer)']. > '</td></tr>'; > } > ?> > </table> > <? > > > do_html_footer(); > ?> > > How can I echo count(referer) ? > > I currently get this error > > Warning: Undefined index: count(referer) in > C:\Inetpub\TecEco_PHP\stats_interface\referer_base.php on line 16 > > > -- > JJ Harrison > webmaster@tececo.com > www.tececo.com > > "Jj Harrison" <webmaster@tececo.com> wrote in message > news:20020709113437.34570.qmail@pb1.pair.com... > > Could some one give me an idea as to what I SQL query could > use to get the > > percentages of each differant colomn value. > > > > ie if this was my table: > > +-------+---+ > > | name | id | > > +-------+---+ > > | foobar | 1 | > > | foobar | 2 | > > | foobar | 3 | > > | barfoo | 4 | > > +-------+---+ > > > > I would get this result(Then later do stuff with it in PHP): > > > > +-------+--------+ > > | name | percent | > > +-------+--------+ > > | foobar | 75 | > > | barfoo | 25 | > > +-------+--------+ > > > > Thanks in advance, > > > > > > -- > > JJ Harrison > > webmaster@tececo.com > > www.tececo.com > > > > > > > > > > > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php >

« previous php.db (#20442) next »