Mysql / PHP / ADODB - echoing SELECT命令返回列名和其他字符

时间:2012-02-23 18:07:20

标签: php mysql ado

我正在尝试从MySQL数据库中获取一些简单的数据。

在phpMyAdmin中执行以下命令可以正常工作:

SELECT coords FROM btDCSimpleMapMarkers WHERE bID = 152

http://i44.tinypic.com/nywy0g.png

但是当我在PHP中尝试相同的时候(动态替换bID):

echo $db->query("SELECT coords FROM btDCSimpleMapMarkers WHERE bID = {$bID}");

我明白了:

"coords
"
"coords
   "55.8858884,-3.5473646","56.1962574,-4.7451167","58.1476532,-5.2027190","55.9714768,-3.1769557","57.6809791,-4.3305414","55.9409414,-3.5107965","56.2444546,-4.2167933","55.5162577,-4.3799082","57.1417936,-2.0930123","55.9699585,-3.1853694","0,0","0,0","0,0","0,0","0,0","0,0","0,0","0,0","0,0","0,0","0,0","0,0","0,0","0,0","0,0","0,0","0,0","0,0","0,0","0,0","55.6459257,-3.1714130","55.8614198,-3.0658253","55.9433622,-3.0590451","55.9563443,-2.7912248","55.8533561,-4.3041345","55.2410909,-4.8555597","55.8577681,-4.2443929","55.8781498,-4.2898555","57.1426478,-2.1232869","56.8705582,-5.4453786","56.1884131,-4.4899996","0,0","0,0","0,0","0,0","0,0","0,0","0,0","0,0","0,0","0,0","0,0","0,0","55.9717258,-3.1931145","55.9491408,-2.7235834","55.8922571,-3.0575724","57.0761811,-2.7793013","56.1888841,-3.0137383","55.6956709,-3.3806546","57.4871048,-4.2490284","56.4125195,-5.4727019","56.0751328,-3.4419449","58.4337677,-3.0813735","0,0","0,0","0,0","0,0","0,0","0,0","0,0","0,0","0,0","0,0","0,0","0,0","0,0","0,0","0,0","0,0","0,0","0,0","0,0","0,0","0,0"
"

我不知道开头的额外内容来自哪里(尤其是列名)。该字段包含一个长字符串,列类型为VARCHAR(20000)。

任何帮助都会受到赞赏,因为我很难过!

1 个答案:

答案 0 :(得分:0)

您似乎试图直接回应mysql结果。

你需要做的是使用mysql_fetch_array()获取每一行数据然后回显。

我就是这样做的:

$sql = "SELECT coords FROM btDCSimpleMapMarkers WHERE bID = 15";
$result = mysql_query($sql);

while($row = mysql_fetch_array($result)){
    echo $row['coords'] . "<br />";
}