Re: [請益] 搜尋全部資料表

看板PHP作者 (台灣獨立公投入聯)時間18年前 (2007/12/25 09:02), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串2/2 (看更多)
table: year94、year95、year96 same fields: birthday,sex,blood_type,...... 要查詢這些表的 王小明 嗎? 這時候就程式去組SQL好像還不錯用 像year...這些table,用日期去產生他的array應該滿簡單 $sql=""; for($i=94;$i<=96;$i++) //--->可自己再看需求改一改就好 { $sql.=" select birthday,sex,blood_type from year".$i." where name='王小明' "; if($i!=96) //若$i是最後一個,就不用產生union了 { $sql.=" union "; } } //上面就可以產生出依查詢的union列了 select birthday,sex,blood_type from year94 where name='王小明' union select birthday,sex,blood_type from year95 where name='王小明' union select birthday,sex,blood_type from year96 where name='王小明' ^﹏^ -- 3WA訓練家的工作室 宗旨:人生就是要爽 個人佈弱格 網址:http://3wa.myvnc.com -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 218.162.80.100

12/26 00:32, , 1F
謝謝你~~~~
12/26 00:32, 1F
文章代碼(AID): #17S5QmFW (PHP)
文章代碼(AID): #17S5QmFW (PHP)