Jump to content
php.lv forumi

Table noteikšana


daviskrex

Recommended Posts

Sveiki, tātad, mēģināju uzcept search skriptu, bet saskāros ar tādu problēmu, ka man vajadzētu kaut kā noteikt no kura table rezultāts ir, jo meklēšana notiek vairākos table'os.

SELECT * From news,forum_posts,forum_topics, members where
news.virsraksts like \"%$qsql%\"
or news.raksts like \"%$qsql%\"
or forum_topics.title like \"%$qsql%\"
or forum_posts.teksts like \"%$qsql%\"
or forum_posts.title like \"%$qsql%\"
or members.profile_name like \"%$qsql%\"
or members.email like \"%$qsql%\"
or members.name like \"%$qsql%\"
or members.surname like \"%$qsql%\" 
order by news.id, forum_topics.id, forum_posts.id, members.id desc

Varbūt kāds var dot kādu padomu kā šo īstenot?

Jau iepriekš pateicos.

Edited by daviskrex
Link to comment
Share on other sites

Tasīt dekarta reizinājumu no visu tabulu ierakstiem, ir drusku aplami...

 

Var izmantot, piemēram, UNION'u:

SELECT "news", virsraksts FROM news WHERE virsraksts LIKE "%qsql%"
UNION
SELECT "forum_topics", title FROM forum_topics WHERE title LIKE "%qsql%"
UNION
...

Vienīgi ierobežojums, ka visiem SELECT'iem jāatgriež vienāds kolonnu skaits.

 

Daudz prātīgāk arī ir neizmantot LIKE keywordu, bet tā vietā taisīt full text search'u: http://dev.mysql.com/doc/refman/5.0/en/fulltext-search.html

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...