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
36
Other forums
Count Session and Trigger Events
I am New in PHP, seeking a method to count logged users by counting the sessions or any …, is
Shuffle Array
Hi,
I am writing a script for a game that needs players to randomly be assigned a target (ano
Searching keywords from array
Hello everyone, Im just wondering if someone could help me with another issue im having. Im still le
need help in dynamic select menu in php
hi i have created a dynamic select menu using php. i have a problem in that which is when the user s
Spliting paragraph into sentences and attach in
Here is what I am trying to do
example: Para1[123.456.789!] 3 sentences
Para2
While Problem
i am having a problem with a while statement here is the code
Code: [Select]<?php
sess
Merger of 6 sister companies under one flagship company after go live
Dear Experts,
I need one help regarding Merger of sister companies of same group. currently we
Multiple server callbacks (NOT POSTBACKS)
Hello,
I have 2 different javascript client side functions that are on timers. When the timers elap
Pagination won't carry results past page 2.
Hi all,
I've worked out my pagination script and its paginating fine until I click next from
Querying info from one table based on info in another
Hi, I am currently trying to make a part for my user driven website where one user can subscribe to