2016-07-06 111 views
1

我想提出一個搜索頁面,我試圖利用工會三個表選擇計數,但我得到的錯誤是這樣 Fatal error: Cannot pass parameter 2 by reference in /home/plooks/public_html/user/test.php on line 106here is my table structure與工會表的SQL查詢SELECT COUNT

表1名>>博文

| bid | title  | body   | author | 
|----- |------- |------------- |-------- | 
| 1  | new  | hello new  | you  | 
| 2  | cast  | broadcast  | me  | 
| 3  | hack  | who hack us | you  | 

表2名>> forumnew

| fid | ftitle | fbody   | user | 

|----- |------- |------------- |-------- | 
| 1  | new forum | hello new  | you  | 
| 2  | cast me | broadcast  | me  | 
| 3  | hack you | who hack him | us  | 

表3名>>下載

| did | file  | disc   | type  | 

|----- |------- |------------- |-------- | 
| 1  | whoweare | hello new  | php  | 
| 2  | cast  | broadcast  | html  | 
| 3  | hack  | who hack us | c++  | 

SQL查詢

SELECT COUNT(id) FROM (
    SELECT 'post' AS type, BID AS id FROM blogpost 
    UNION 
    SELECT 'jail' AS type, jid AS id FROM forumnew 
    UNION 
    SELECT 'article' AS type, TID AS id FROM download 
)csl WHERE title LIKE :search OR title LIKE :search") 
+0

哪個表有description列? – artm

+0

@artm我編輯了我的帖子 – Frank

+0

你的代碼是什麼樣的?類似的問題:http://stackoverflow.com/questions/8287581/how-to-resolve-cannot-pass-parameter-by-reference-error-in-php#autocomment44785441 – mulquin

回答

1

有查詢一個錯誤,你沒有title在臨時表csl,所以它不能用在WHERE條款中。另外第二個OR title LIKE :search是多餘的。如果你不想做一個截然不同的這個id,那麼你不需要其他的列,只有標題列才能過濾,結果將是一樣的。

SELECT COUNT(*) FROM (
    SELECT title FROM blogpost 
    UNION 
    SELECT ftitle AS title FROM forumnew 
    UNION 
    SELECT disc AS title FROM download 
) csl WHERE title LIKE :search 

SELECT 
    (SELECT COUNT(*) FROM blogpost WHERE title LIKE :search) + 
    (SELECT COUNT(*) FROM forumnew WHERE ftitle LIKE :search) + 
    (SELECT COUNT(*) FROM download WHERE disc LIKE :search)