I'm currently having trouble printing some simple test statements within my for loop.
<?php
include('../connstr.inc');
$email=$_REQUEST["email"];
$datafile=$_REQUEST["datafile"];
$email_safe=preg_replace("/[^a-zA-Z]/","_",$email);
$path="../uploaded_data";
$xml = simplexml_load_file("{$path}/{$email_safe}/{$datafile}.xml");
// Retreive data details for specified activity
$lapcount = $xml->Activities->Activity->Lap->count();
echo "LapCount: " . $lapcount;
$totalTime = array(); $distance = array(); $maxSpeed = array();
$calories = array(); $intensity = array(); $trigMethod = array();
echo 'Test1';
// Collect details for each lap
for($x = 0; $x < $lapCount; $x++) {
echo 'Test2';
// Find how many trackpoints exist for specified lap
$trackPointCount = $xml->Activities->Activity->Lap[$x]->Track->Trackpoint->count();
echo 'Test3';
echo "<br /> Lap {$x} TrackP Count: " . $trackPointCount;
echo 'Test4';
}
When I run it, only 'Test1' and the 'lapCount' gets printed. Anything within the for loop doesn't run. No errors are being returned either. $x will definitely be less then $lapCount as this is just 3. I fail to see the (most likely) stupid mistake I've made even after looking over it many times.
The problem with your code is this:
You declare lapcount as $lapcount, but try using it as $lapCount (Notice the capitalization of the "C")
Ensure all uses of this variable are typed out exactly the same and everything will work
EDIT: Seems like you discovered this as I posted my answer
Initially you are using variable name $lapcount
but in the last for loop you are using $lapCount
that is the reason why you are not getting any value. Use $lapcount in the last for loop also.
for($x = 0; $x < $lapcount; $x++) { // use $lapcount
echo 'Test2';
$trackPointCount = $xml->Activities->Activity->Lap[$x]->Track->Trackpoint->count();
echo 'Test3';
echo "<br /> Lap {$x} TrackP Count: " . $trackPointCount;
echo 'Test4';
}
Here, the name of your var is $lapcount without 'C' lowercase:
// Retreive data details for specified activity
$lapcount = $xml->Activities->Activity->Lap->count();
echo "LapCount: " . $lapcount;
but here, you use 'C' uppercase, $lapCount:
for($x = 0; $x < $lapCount; $x++) {