For some reason my php while loop is printing out the data twice and I cannot seem to figure why this is. Here is my code:
<?php
$json = '[';
$query = "SELECT user_id, first_name, last_name, phone, phone_two, email FROM customers LIMIT 20";
$result = mysqli_query($dbc, $query);
while($row = mysqli_fetch_array($result, MYSQLI_BOTH)) {
$json .= "{ num: \"{$row['user_id']}\" },{ num: \"{$row['first_name']}\" },{ num: \"{$row['last_name']}\" },{ num: \"{$row['phone']}\" },{ num: \"{$row['phone_two']}\" },{ num: \"{$row['email']}\" },";
}
//Remove the last trailing comma
$json .= substr($json, 0, -1);
$json .= ']';
echo $json;
?>
When I echo the results out to the web browser, instead of having 20 customers, I have 40. However, it is the first 20 customers listed twice. I have no clue what could be causing this to happen.
json_encode.