How can I not return an "X" value in DB?

0

How do I not return an "X" value in the database?
For example, I have a Vagalume style website, and it has the page of each artist where the tab "Related Artists" is based on the TAGs registered in the BD, I wanted it not to return the artist value of the current page.

    
asked by anonymous 04.05.2018 / 04:38

2 answers

4

If you refer to SQL, just use for example:

SELECT * FROM tabela_artistas WHERE id_artista <> id_artista_atual
    
04.05.2018 / 06:07
2

You can do it in two ways:

Simple, filtering 1 record:

$query = 'SELECT * FROM tb_artistas WHERE id <> $id';

Example of the expected result of the query:

SELECT * FROM tb_artistas WHERE id <> 27

or if you bring more than 1 record, separated by commas:

$query = 'SELECT * FROM tb_artistas WHERE id NOT IN ($ids)';

Example of the expected result of the query:

SELECT * FROM tb_artistas WHERE id NOT IN (25,84,64,86)

Filtering multiple records for a more formulated search (eg with TAG):

$query = 'SELECT * FROM tb_artistas WHERE id <> $id AND tag IN (tags)';

Example of the expected result of the query:

SELECT * FROM tb_artistas WHERE id <> $id AND tag IN (2,5,8,10)
    
04.05.2018 / 12:44