php - MySQL join two table matching with their id -


i have 2 table:

table one: user

id   name   home_location    job_location 1    jack   40               5 2    rocky  50               4   3    tom    24               9 

table two: area

area_id    area_name 5          bukit batok 4          bukit panjang 9          boon lay 40         pioneer 50         choa chu kang 24         clementi 

i want result this:

id    name    home_location   job_location 1     jack    pioneer         bukit batok 2     rocky   choa chu kang   bukit panjang 3     tom     clementi        boon lay 

as not in sql query how write select query. ideas or suggestions? thanks.

try

select id id,              name,              area_1.area_name home_location,              area_2.area_name job_location,              area_1.area_id home_location_id,              area_2.area_id job_location_id    user  inner join        area area_1             on area_1.area_id = user.home_location inner join        area area_2            on area_2.area_id = user.job_location 

and try avoid mysql_* statements due entire ext/mysql php extension, provides functions named prefix mysql_*, officially deprecated of php v5.5.0 , removed in future.

there 2 other mysql extensions can better use: mysqli , pdo_mysql, either of can used instead of ext/mysql.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -