2012-07-28 112 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