Frage

I have this scenario in my MySQL database: enter image description here

I need select row where tag is from url parameter (GET) with php-mysql query:

$tag = $_GET['tag'];
// example $tag = 1
// now I need select rows where in tags colums is value 1. 

How can I obtain this query? I think that I need create an array... but I dont know how do. thanks in advance!

War es hilfreich?

Lösung 2

Don't do it this way - it will create trouble for you with every query until you fix it.

Instead, make a table of tags, and use a many-to-many relationship to associate teams with tags.

For example

CREATE TABLE tag (
    id int not null auto_increment primary key,
    name varchar(100),
    description varchar(255) );

CREATE TABLE teamtag (
    team_id int,
    tag_id int,
    CONSTRAINT 'team_fk' FOREIGN KEY (team_id) REFERENCES team ('id'),
    CONSTRAINT 'tag_fk' FOREIGN KEY (tag_id) REFERENCES tag ('id') );

Andere Tipps

You can do that using LIKE/FIND_IN_SET but you definitely shouldn't.

Instead consider changing schema and adding dictionary table to keep all tags and join table to keep all connections between tags and items.

SELECT * FROM `table` WHERE FIND_IN_SET(`Tags`, '$tag') > 0;
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top