How do I echo out something different when reached last row?

Posted by Josh Brown on Stack Overflow See other posts from Stack Overflow or by Josh Brown
Published on 2010-04-16T14:38:03Z Indexed on 2010/04/16 14:43 UTC
Read the original article Hit count: 281

Filed under:
|
|

I am wanting to not echo out the comma at the end of the echo after the last row. How can I do that? Here is my code:

<?php
    header("Content-type: application/json");
    echo '{"points":[';

    mysql_connect("localhost", "user", "password");
    mysql_select_db("database");

    $q = "SELECT venues.id, venues.lat, venues.lon, heat_indexes.temperature FROM venues, heat_indexes WHERE venues.id = heat_indexes.venue_id";

    $res = mysql_query($q) or die(mysql_error());
    while ($point = mysql_fetch_assoc($res)) {
    echo $point['lat'] . "," . $point['lon'] . "," . $point['temperature'] . ",";
    }
    mysql_free_result($res);
    echo ']}';
    ?>

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql