mysql - PHP CodeIgniter - how to get good result array when relational table (there are same column name in different table)


I am trying to make pretty query result like doctrine, and other ORM

for example with relational table article and article_category.

i want to get query result like this :

    [0] => Array 
          [id] => 1
          [title] => I am article title
          [slug] => i-am-article-title
          [category] => Array
                     [id] => 1
                     [name] => Category Name
                     [slug] => category-name

    [1] => Array 
          [id] => 2
          [title] => How to coding
          [slug] => how-to-coding
          [category] => Array
                     [id] => 4
                     [name] => Tutorial Area
                     [slug] => tutorial-area


i know this is basic, but i am want to know for create that result in very simple way.

thanks for all advice


for to get that result, I am change using eloquent laravel framework.. . :)




No, you can't get this information in this way directly from your database if you are using a Relational Database like MySQL or PostgreSQL

You can get the effect you wish in two queries and insert the subquery array to your result array, or you can have a different table for your categories and do a JOIN with SQL.

As a note, other database systems return just what you asked, consider switching to MongoDB (a No-SQL solution) it returns an object just like you wished

People are also looking for solutions to the problem: php - Send variable to the user profile in Drupal 6


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.