Hello guys i have these tables;
USERS( user_id ,fullname ,username etc.)
POSTS ( post_id, user_id, post, orig_post_id, replyto date)
USER_PROFILE (id, user_id, profile_image_path etc)
Examples
USERS (1 ,John Doe ,johndoe etc.),( 2 ,Stack Flow ,stackflow etc.)
POSTS (2, 1, My naame is John doe and i approve this message, 0, 0,sometimestamp),
(3, 12, My naame is Stack Flow and i approve this message, 0, 2,sometimestamp)
USER_PROFILE (1, 1, ppdjodjf.jpg etc),(2, 2, grsdjodjf.jpg etc)
Basically, i want the query to output this if the replyto field is 0
array('post_id' => 2,
'user_id' => 1,
'post' => the post,
'orig_post_id,' => 0
'replyto,' => 0
username => johndoe,
fullname => John Doe,
profile_image_path => etc)
And when it’s not zero
array('post_id' => 3,
'user_id' => 2,
'post' => Another post,
'orig_post_id,' => 0
'replyto,' => 2
username => stackflow,
fullname => Stack Flow,
profile_image_path => etc,
'replies' => array(all the replies)
After spending the whole day on this, My code ended up looking like this.
I know this looks different from the question i asked but i was trying to simplfy what i was actually doing.I didn’t think asking a question stating this problem would get me anywhere, although simplyfying the question still didn’t get me anywhere as no one understood me haha. For my question anyway, the relevant part is the last bit of the code where i put a condition ssaying if branch_id is not zero get some array data and if it is return an empty array.The I merged the array together with then query result.
Now i have to think of how i can simplyfy this.