2012-07-28 114 views
0
while($row = mysql_fetch_array($result)) 

此刻我的$ row ['content']里面有四个字符串,我怎么才能让它们进入数组中的单独对象?

如0>“第一个”

1>“第二个字符串” 等等

此刻他们都捆绑成一个似乎...但我需要他们分隔在一个数组中。

我是PHP的新手,并花了很多时间试图找出如何做到这一点。

在此先感谢。

print_r($ row ['content']);

返回:

的hello world另一个oneand另一个...更多即将... $行的回报

VAR转储:

阵列(4){[0] =>字符串(1)“1”[“id”] =>字符串(1)“1”[1] =>字符串(12)“hello world!” [“content”] => string(12)“hello world!” } array [4] {[0] => string(1)“2”[“id”] => string(1)“2”[1] => string(11)“another one”[“content”] => string(11)“another one”} array(4){[0] => string(1)“3”[“id”] => string(1)“3”[1] => string(18 )“和另一个...”[“content”] => string(18)“and another one ...”} array(4){[0] => string(1)“4”[“id” ] => string(1)“4”[1] => string(14)“more coming ...”[“content”] => string(14)“more coming ...”}

+0

var_dump($ row)'show? – 2012-07-28 18:02:12

+0

'explode(“\ n”,$ row ['contents'])'? – 2012-07-28 18:03:24

+0

你能否添加一些关于你的数据库模式的信息? – Thomas 2012-07-28 18:04:33

回答

3

TRY

while($row = mysql_fetch_array($result)) 
{ 
    $output[] = $row['content']; 
} 
echo "<pre>"; 
print_r($output); 
+0

根本没有分隔符,这是我想的概率。干杯。 – bobster 2012-07-28 18:12:08

+0

没有分隔符你怎么区分有4个字符串? – diEcho 2012-07-28 18:13:21

+0

,因为它是从我有四个单独条目的数据库中提取的,因此出于某种原因将它们捆绑在一起。 – bobster 2012-07-28 18:13:57

-3

编辑:我看错了,对不起。如果你的字符串用逗号隔开,那么这就足够了:

$array = explode(',', $row['content']); 
+0

没有逗号:( – bobster 2012-07-28 18:11:38

+1

-1'explode'错误语法 – diEcho 2012-07-28 18:12:38

+0

@diEcho:你说的对,我很抱歉。 你可以提供一些关于如何将数据放入数据库的信息吗?只有当我们知道有什么样的数据时才解决(我认为)。如果你作为一个人,不能分开这些琴弦,那么当然,电脑不能:) – 2012-07-28 18:31:52