php - Inner join vs foreach loop performance -


i'm trying , i'm sure if i'm doing in right way. let's have 2 tables in mysql database following columns

-------------------------

members ------------------------- id        name      status -----     -----     ----- 1         mike      0 2         alex      0 3         john      1 4         jack     -1 

-------------------------

    status     -------------------------     id        text     -----     -----    -1        disapproved     0         reviewing     1         approved 

now need display information of table "members" in following way:

id        name      status -----     -----     ----- 1         mike      reviewing 2         alex      reviewing 3         john      approved 4         jack      disapproved 

one way use inner join between 2 tables , other way extract data "members" table , put inside for-each loop , convert status values. in latter way don't need "status" table @ all.

i'm not sure way better. please let me know if need more information me.

thanks in advance.

update

an for-each example want this, supposing have extracted data "memberes" table

foreach($data $value)     {     if ($value['status'] == 0)         $value['status'] = 'reviewing';     if ($value['status'] == 1)         $value['status'] = 'approved';           else         $value['status'] = 'diapproved';             } 

in general, absolutely want doing via join inside mysql database:

select     t1.id, t1.name, t2.text status members t1 inner join status t2     on t1.status = t2.id 

the alternative of handling inside php code foreach loop unattractive several reasons. first, need bring in information both tables, wasteful both memory , network usage point of view. then, after have brought in data, relying on php perform join. php wasn't designed in house database operations, , cannot use index speed process.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

.htaccess - ERR_TOO_MANY_REDIRECTS htaccess -