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.
精彩评论