php - MySQL searching files by file name, tags, file category and author

220

I'm doing something like youtube.

How to do searching for file?

My database structure:

Files:

ID (PK)
AuthorID (FK)
Name  varchar

FileToCategory

ID(PK)
FileID(FK)
CatID(FK)

TagsToFile

ID(PK)
FileID(FK)
Tag varchar
  1. I would like to let user type something in search textbox and then display him best result according to file name and tags.
  2. When user is watching some file I want to show him proposed files list according to file names, tags, category(same as actual file) and author.

How to do that? I would appreciate any code or natural language explanation how to do that.

EDIT

AD. 1

Something like that works but it does not use file name, how to change it?

SELECT f.ID, f.Name, count( t.ID ) AS HowsGood
FROM Files f
LEFT OUTER JOIN TagsToFile t ON f.ID = t.FileID

AND t.Tag
IN (
'lucky', 'wow', 'ninja', 'cat'  -- example of searched words
)
GROUP BY f.ID, f.Nazwa
order by count(t.ID) desc
982

Answer

Solution:

You could use something like that.

SELECT DISTINCT a.ID, a.Name
FROM Files a, TagsToFile b
WHERE a.ID = b.FileID
AND (a.Name LIKE '%search%' OR b.Tag LIKE '%search%');

People are also looking for solutions to the problem: php - Using Google Sheets as a database?

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.