0

First sorry if the question is bad my english is not too good.

I have the following query

SELECT 
    * 
FROM 
    `stream_post` 
        LEFT JOIN `stream_comment` 
            ON (`stream_post`.`stream_id` = `stream_comment`.`comment_stream_id`) 
        JOIN `users_metadata` 
            ON (`stream_post`.`user_id` = `users_metadata`.`user_id`) 
ORDER BY 
    `stream_id` DESC 
LIMIT 10

And the porblem actually is i would like to use these for comments on the same page

So it would look like this

parrent post 1
   children comment 1
   children comment 1

parrent post 2
   children2 comment 1
   children2 comment 1

And i save the post id (what is the stream id) i the comments table too and join them.

but when i get the results ut looks like this

Array
(
    [stream_id] => 1
    [user_id] => 1
    [stream_text] => dasdadada
    [date] => 1346400535
    [comment_id] => 1
    [comment_stream_id] => 1
    [comment_user_id] => 1
    [comment_text] => comment one
    [posted] => 0
    [full_name] => Henry Marg
    [gender] => 1
    [location] => Los Angeles
    [birth_year] => 2012
    [birth_month] => 1
    [birth_day] => 1
    [work_location] => Tesco
    [about] => Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.

The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.
)


Array
(
    [stream_id] => 1
    [user_id] => 1
    [stream_text] => dasdadada
    [date] => 1346400535
    [comment_id] => 1
    [comment_stream_id] => 1
    [comment_user_id] => 1
    [comment_text] => comment 2
    [posted] => 0
    [full_name] => Henry Marg
    [gender] => 1
    [location] => Los Angeles
    [birth_year] => 2012
    [birth_month] => 1
    [birth_day] => 1
    [work_location] => Tesco
    [about] => Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.

The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.
)

so the problem is when i freach these, i get the comment seperated, insted of merged?

so i would like to look like this

A

rray
(
    [stream_id] => 1
    [user_id] => 1
    [stream_text] => dasdadada
    [date] => 1346400535
    [comment_id] => 1
    [comment_stream_id] => 1
    [comment_user_id] => 1
    [comment_text] => comment one
    [comment_text] => comment two
    [posted] => 0
    [full_name] => Henry Marg
    [gender] => 1
    [location] => Los Angeles
    [birth_year] => 2012
    [birth_month] => 1
    [birth_day] => 1
    [work_location] => Tesco
    [about] => Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.

The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.
)

Is there a way to do this? Could please someone give me a hint or an example?

Would be really happy

Fluffeh
  • 33,228
  • 16
  • 67
  • 80
Side
  • 1,753
  • 9
  • 35
  • 64

2 Answers2

0

Sorry to say but that is how it goes. Unless you put all your data inside an array, then you can use a foreach or for statement to go through the comment_text in order.

Mic1780
  • 1,774
  • 9
  • 23
0

You can't have two keys with the same name in an array. You would need to rename the keys as you went (probably appending a number to the end)

[comment_text_1] => comment one
[comment_text_2] => comment two

OR you could turn each element into an array of sub elements like this- which is much more useful in code

[comment_text] => array('comment one', 'comment two') 
msEmmaMays
  • 1,073
  • 7
  • 7