This is strange...
I have a query that goes to MySQL and returns a resultset. I then go through that result set with a "do...while" loop. It should only run for as many rows as are returned by the query. However, in my tests, only one row is being returned (which is correct), yet the loop seems to insert an extra null value in the array before adding the values from the array. Here's my code to show you what I mean:
The problem here is that count($arrayJobServices) returns one more than $totalRows_JobServices. The first value in the array is an empty value. Any ideas why this is happening? I've used code similar to this before and didn't have this problem... any help you can give is MUCH appreciated!
I have a query that goes to MySQL and returns a resultset. I then go through that result set with a "do...while" loop. It should only run for as many rows as are returned by the query. However, in my tests, only one row is being returned (which is correct), yet the loop seems to insert an extra null value in the array before adding the values from the array. Here's my code to show you what I mean:
Code:
$query_JobServices = "SELECT * FROM jobsServices js
LEFT JOIN services s ON s.serviceID=js.serviceID
WHERE jobID=".$row_clientsJobs['jobID']."
ORDER BY service";
$JobServices = mysql_query($query_JobServices, $db_cpdatabase) or die(mysql_error());
$totalRows_JobServices = mysql_num_rows($JobServices); // this is returning CORRECTLY
$arrayJobServices = array();
do {
array_push($arrayJobServices, $row_JobServices['service']);
} while ($row_JobServices = mysql_fetch_assoc($JobServices));
The problem here is that count($arrayJobServices) returns one more than $totalRows_JobServices. The first value in the array is an empty value. Any ideas why this is happening? I've used code similar to this before and didn't have this problem... any help you can give is MUCH appreciated!