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

时间:2021-05-16 03:54:04

I'm having a 'mare trying to get some simple data from my MySQL database.

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

Executing the following command in phpMyAdmin works fine:

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

SELECT coords FROM btDCSimpleMapMarkers WHERE bID = 152

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

but when I attempt the same in PHP (where bID is dynamically substituted):

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

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

I get this:

我明白了:

"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"
"

I don't know where the extra stuff at the beginning is coming from (especially the column name). The field contains one long string, and the column type is VARCHAR(20000).

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

Any help would be appreciated, cos I'm stumped!

任何帮助将不胜感激,因为我很难过!

1 个解决方案

#1


0  

You seem to be trying to echo the mysql result directly.

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

What you need to do is use mysql_fetch_array() to get each row of data and then echo that.

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

This is how I would do it:

我就是这样做的:

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

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

#1


0  

You seem to be trying to echo the mysql result directly.

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

What you need to do is use mysql_fetch_array() to get each row of data and then echo that.

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

This is how I would do it:

我就是这样做的:

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

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