0
while($row = mysql_fetch_array($result))

At the moment my $row['content'] has four strings inside it, how can I get them into seperate objects in an array?

As in 0 > "first string"

1 > "second string" etc...

At the moment they are all bundled into one it seems... But I need them seperated in an array.

I am new to PHP and have spent ages trying to find out how to do this.

Thanks in advance.

print_r ($row['content']);

Returns:

hello world!another oneand another one...more coming...

var dump of $row returns:

array(4) { 
    [0]=> string(1) "1" 
    ["id"]=> string(1) "1" 
    [1]=> string(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) "and another one..." 
    ["content"]=> string(18) "and another one..." 
} array(4) {
    [0]=> string(1) "4" 
    ["id"]=> string(1) "4" 
    [1]=> string(14) "more coming..." 
    ["content"]=> string(14)
}
4
  • What does var_dump($row) show? Commented Jul 28, 2012 at 18:02
  • explode("\n", $row['contents'])? Commented Jul 28, 2012 at 18:03
  • Would you please add some information about your db schema? Commented Jul 28, 2012 at 18:04
  • what is the separator of these 4 strings? Commented Jul 28, 2012 at 18:06

2 Answers 2

3

TRY

while($row = mysql_fetch_array($result))
{
  $output[] = $row['content'];
}
echo "<pre>";
print_r($output);
Sign up to request clarification or add additional context in comments.

11 Comments

there are no separators at all, that's the prob I think. Cheers.
without separator how do you distinguish that there are 4 string??
because it's pulled from a database where I have four separate entries, it's bundled them together for some reason.
which mySQL function you use to build them while retrieving? CONCAT
there should be, may be space
|
-3

EDIT: I read it wrong, sorry. If your strings are seperated by a comma then this will suffice:

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

1 Comment

@diEcho: You're right, i'm sorry. Can you give some more info on how the data is put in the database? This problem is only solved (i think) when we know what kind of data there is. If you, as a human being, can't separate the strings, than sure as hell a computer can't :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.