General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old April 2nd, 2003, 07:49 PM
zigote zigote is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Location: Atlanta GA
Posts: 73 zigote User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 55 m 11 sec
Reputation Power: 7
Getting The Average

Say I have a number is a table.
How would I divide a number that I pulled from a table and divide by what day it is, to get the average since the beginning of the week.

Day 4: Wednesday - 50 in table
Number in table: 50, mysql_query: 50 divide that by 4[day] = Average: 12.5
_________________________________
this is what I have so far... not sure if I'm doing this right...

get the day
PHP Code:
 $today date("l");
  if(
$today == "Sunday"
  {
     
$xDay "1";
  }
  elseif(
$today == "Monday")
  {
     
$xDay "2";
  } 
  elseif(
$today == "Tuesday"
  {
     
$xDay "3";
  } 
  elseif(
$today == "Wednesday")
  {
     
$xDay "4";
  } 
  elseif(
$today == "Thursday")
  {
     
$xDay "5";
  } 
  elseif(
$today == "Friday"
  {
     
$xDay "6";
  }
  elseif(
$today == "Saturday")
  {
     
$xDay "7";
  } 
  else 
  {
  }
________________________________________
get the total from mysql
$day_avg 
get_data_array("SELECT...

here's where I divide..
$total = $day_avg;
$day = $xDay;
$average = $total / $day; 


then, print("$average");

Last edited by zigote : April 2nd, 2003 at 10:08 PM.

Reply With Quote
  #2  
Old April 6th, 2003, 12:42 PM
FrankieShakes FrankieShakes is offline
Frank The Tank!
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Jun 2002
Location: Toronto, Canada
Posts: 1,246 FrankieShakes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Send a message via ICQ to FrankieShakes Send a message via MSN to FrankieShakes
You can use the date() function to retrieve the day in the week (number value):

PHP Code:
 $xDay date("w"); // Returns 0 for Sunday through to  6 for Saturday

// Your SQL Query here.... 


$total $day_avg;

$average $total $xDay


If you want to use 1 for Sunday and 7 for saturday, just add 1 to the value of $xDay.

HTH!
__________________
____________________________________________
Developer Shed Weekly Writer | DevArticles Forum Moderator
Build Your Own KlipFolio Klip With PHP
FrankManno.com - Under Construction
Design Interactive Group - Under Construction

Reply With Quote
  #3  
Old April 6th, 2003, 10:50 PM
zigote zigote is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Location: Atlanta GA
Posts: 73 zigote User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 55 m 11 sec
Reputation Power: 7
very cool thanks, that helps alot

Reply With Quote
  #4  
Old April 13th, 2003, 02:03 PM
FrankieShakes FrankieShakes is offline
Frank The Tank!
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Jun 2002
Location: Toronto, Canada
Posts: 1,246 FrankieShakes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Send a message via ICQ to FrankieShakes Send a message via MSN to FrankieShakes
Not a problem... Glad I could help!

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > Getting The Average


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway