Page 1 of 1

php percent help

Posted: Mon Jan 24, 2011 4:32 pm
by twistajones53
i would like to figure out the number of times my business breaks even on a daily percentage

so say we had 21 days and 12 of those days had profit i would like to have it dynamically update on our site to 57.1%

i have created a table just for this function with each day getting a separate entry

table layout

id | date | profit
x | 2011-10-4 | 54.76

i have the code below to return our first variable of 12, but after that i'm not getting anywhere after a few days


PS I would also love to know how to rid myself of this table (as i have to enter a record once daily) and be able to sql our entire database using GROUP BY 'date'
to find the number of positive days then just divide by the total number of GROUP BY 'date' results but i have no idea how to do that in php code

any help is much appreciated

Code: Select all

<?php 
$query= "SELECT COUNT(date) FROM daybyday WHERE units >'0'";
$sql = mysql_query($query);
$countArray = mysql_fetch_array($sql);
$rows = $countArray[0];
//
echo $rows;
?>

Re: php percent help

Posted: Mon Jan 24, 2011 5:16 pm
by califdon
For using the WHERE clause to select only certain records:
http://www.w3schools.com/sql/sql_where.asp

For getting the number of records, use COUNT():
http://www.w3schools.com/sql/sql_func_count.asp