Completely stumped by this one. I have some code that pulls rows from a database and attempts to process them as part of a PHP while() loop. Here's the basic code:
$i = 1;
while (list($thisScoreID, $thisClassifier, $thisRAW) = mysqli_fetch_array($r, MYSQLI_NUM)){
// Grab the reference time that's relevant to this iteration of the loop
$thisReference = $referenceArrayL6[$thisClassifier];
// Calculate a percentage from scratch, using the reference time and RAW score
$thisPercent = 50.00;
echo "Line ".$i." of data...", PHP_EOL;
$i++;
There are 4529 lines of data in the table and when I run it as shown (via command line) it shows the correct number of lines, i.e., the last line shows as "Line 4529 of data..."
However, I don't actually want to hard-code the percentage. I want to do a calculation to update an old percentage with a new percentage. Here's the version of the code that I actually want to run:
$i = 1;
while (list($thisScoreID, $thisClassifier, $thisRAW) = mysqli_fetch_array($r, MYSQLI_NUM)){
// Grab the reference time that's relevant to this iteration of the loop
$thisReference = $referenceArrayL6[$thisClassifier];
// Calculate a percentage from scratch, using the reference time and RAW score
$thisPercent = (($thisReference / $thisRAW)*100);
$thisPercent = number_format($thisPercent,3);
echo "Line ".$i." of data...", PHP_EOL;
$i++;
What's wild is that, this code now skips 98 records. It returns "Line 4431 of data..." as the final line. It's not that the change for a hard-coded value to a dynamic value is a problem; I can change the operator to addition or multiplication and it works fine.
When I discovered that multiplication worked, I tried to multiply by reciprocal instead of dividing, but that also led to failure.
I've identified that none of the values in the database are zero, so it's not related to a "divide by zero" issue.
The only clue I've been able to find is that it's a recent development. The scores go back to 1999 and we changes how they are entered very recently. It appears that, out of the last 124 scores, 26 "work" and 98 get skipped. But when I look at those scores, they appear to be just normal non-zero numbers like the older scores.
I know this has to be related to the change in how we're inputting the scores, but since the scores still appear to be normal non-zero numbers (and they are typed as numbers, not strings) I am stumped as to what could be causing this issue.
I have searched quite a bit on StackOverflow and other sites, but either I'm using the wrong search terms or this is not a common problem; I haven't been able to find anything remotely useful.
Any help would be appreciated. Thanks.
@Barmar suggested that I print out the variable data, just to confirm their values. I had already ran a search to verify that there was no zero values, but I hadn't thought to check for NULL values. One of the values turned out to be NULL and that was causing a divide-by-zero issue. Once I flagged that data as unusable and re-ran the script, everything fell into place.