Display the user's weight lost in the past week


Posted on 16th Feb 2014 07:03 pm by admin

Hello everyone,

I am working on a weight loss app for my site, and I want to display the user's weight lost in the past week, I have the current weight and the total weight lost today working great, but I was at a loss on how to get the weight for the past week to work

Did you know?Explore Trending and Topic pages for more stories like this.
Here is the code that I'm working with:Code: [Select]mysql_select_db($database_getfit, $getfit);
$query_getfit_xml = "SELECT * FROM jos_my_weight ORDER BY `date` DESC"; // DESC and ASC
$getfit_xml = mysql_query($query_getfit_xml, $getfit) or die(mysql_error());
$row_getfit_xml = mysql_fetch_assoc($getfit_xml);
$totalRows_getfit_xml = mysql_num_rows($getfit_xml);

// START WEIGHT
$start_weight = '230';

// GOAL WEIGHT
$goal_weight = '175';

$rows = array();
while($row = mysql_fetch_assoc($getfit_xml)):
$rows[] = $row;
endwhile;

$xml = '<?xml version="1.0" encoding="utf-8"?>'."n";
$xml .= '<chart>'."n";
$xml .= ' <chart_data>'."n";

// GET DATES
$xml .= ' <row>'."n";
$xml .= ' <null/>'."n";
foreach($rows as $row):
$xml .= '<string>'.$row['date'].'</string>'."n";
endforeach;
$xml .= ' </row>'."n";

// GET CURRENT WEIGHTS
$xml .= ' <row>'."n";
$xml .= ' <string>Current Weight</string>'."n";
foreach($rows as $row):
$xml .= '<number>'.$row['weight'].'</number>'."n";
endforeach;
$xml .= ' </row>'."n";

// GET TOTAL WEIGHT LOST TO DATE
$xml .= ' <row>'."n";
$xml .= ' <string>Total weight lost to date</string>'."n";
foreach($rows as $row):
$weight_lost = $start_weight - $row['weight'];
$xml .= '<number>'.$weight_lost.'</number>'."n";
endforeach;
$xml .= ' </row>'."n";

// GET WEIGHT LOST THIS WEEK
$xml .= ' <row>'."n";
$xml .= ' <string>Total weight lost to date</string>'."n";

$i = 0;
foreach($rows as $row):
$xml .= '<number>'.$row['weight'].'</number>'."n";
$i++;
endforeach;

$xml .= ' </row>'."n";

$xml .= ' </chart_data>'."n";
$xml .= '</chart>';

echo $xml;

mysql_free_result($getfit_xml);
No comments posted yet

Your Answer:

Login to answer
146 Like 36 Dislike
Previous forums Next forums
Other forums

how to load a Sys file with system load and call images?
normally you need register the module as a service with CreateService, and start the service

unexpected T_STRING
error log "[Sat Jan 09 18:27:58 2010] [error] [client 127.0.0.1] PHP Parse error: syntax error

Revoking alter any table from a schema
Hi All,

i am working in Oracle 10g.
my requirement is to revoke all kind of DDL oper

Help with translating C code into assembler code
Hi im doing a project that moves a robot around a maze avoiding walls and need some help with conver

code help - pagination
Hi all, I have this code, basically a user logs into my site and they get this page.

The pro

Give me all your tricks for minimizing jar file size

Hi, I'm coming close to releasing my J2ME game... I am kicking up against the 64k size barrier w

PHP Code / Script To check weather the given email exists in a domain
Hi,

I want to implement the following in my web page

in sign up we will ask to enter u

CHECK A STRING FOR ' " ' (DOUBLE QUOTES)
I am checking for delimiter (.!?) and if there is a " after a sentence then it should neglect a

Add a sign-up feature to a flat file login script
I'm working on a flat file login script and I would like to add a sign-up feature to it with a email

Code Review - SQL and Insertion Attacks (Warning: Not for Newbs)
Hey guys,

Its been a while, I know. Use to love coming here to answer peoples questions, but

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash