Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
334 views
in Technique[技术] by (71.8m points)

php - Combining several database table together?

I have two tables tour_foreign&tour_foreign_residence in database and want merger this two table together that get output from PHP code as following example:

My tables and values it:

enter image description here enter image description here

I want get as output tour_foreign.id = tour_foreign_residence.relation :

One-week tour of Istanbul_1 | 88888 & 99999 $ 112233 $ 445566 | Three nights and two days | 15:29
One-week tour of Istanbul_2 | 55555 & 66666 $ 77777 | Three nights and two days | 12:03
One-week tour of Istanbul_3 | 11111 & 22222 $ 33333 $ 44444 | Three nights and two days | 12:03

My try is this but it don't give to me what that I want in above:

$this -> db -> query("
    SELECT
           @rownum := @rownum + 1 rownum,
           tour_foreign.id, 
           tour_foreign.name, 
           tour_foreign_residence.name_re,  
           tour_foreign.term,
           tour_foreign.time_go, 
           tour_foreign.time_back,
           tour_foreign.type_of_vehicle
    FROM   tour_foreign 
           INNER JOIN tour_foreign_residence 
             ON ( tour_foreign.id = tour_foreign_residence.relation )
           JOIN (SELECT @rownum := 0) r
    WHERE  tour_foreign.name LIKE "%' . $find . '%" 
            OR tour_foreign_residence.name_re LIKE "%' . $find . '%"    
")

How can fix it?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Try using GROUP_CONCAT() to join the names from you tour_foreign_residence table


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...