开发者

Plotting points on a map using PHP and MySQL

I'm 开发者_Python百科trying to plot points on a map feature on my new project, but I've run into a problem.

This is my code select code so far:

$latest = mysql_query("SELECT * FROM `database` WHERE `id` = '887584' ORDER BY `id` DESC LIMIT 0,100") or die(mysql_error()); 
while ($lat = mysql_fetch_array($latest)) {

// Missing Part

}

What I'm trying to do is plot the coordinates of my map by using this array:

$coordinates = array (
"$lat[lat]|$lat[long]", "$lat[lat]|$lat[long]", "$lat[lat]|$lat[long]",
);

But I'm not sure how to repeat the coordinates from my database using the php.

Can anybody help?


$coordinates = array();

$latest = mysql_query("
    SELECT
        `lat`
        ,`long`
    FROM
        `database`
    WHERE
        `id` = '887584'
    ORDER BY
        `id` DESC
    LIMIT 0,100
") or die(mysql_error()); 
while ($row = mysql_fetch_assoc($latest)) {
    $coordinates[] = implode('|', array($row['lat'], $row['long'])); // Could be
        // shortened to implode('|', $row), but if you select more fields
        // in the future it will likely break your app.
}


I'm not quite sure what you're asking for, but it looks like you're having the code more or less written out already. I think this is what you want:

$coordinates = array();
$query = mysql_query("SELECT `lat`, `long` FROM `database` WHERE `id` = '887584' ORDER BY `id` DESC LIMIT 0,100") or die(mysql_error());
while ($row = mysql_fetch_assoc($query)) {
    $coordinates[] = $row['lat'] . "|" . $row['long'];
}

By the way, if `database`.`id` is a primary key and/or unique, then you don't need the ORDER and LIMIT part of the query.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜