How not to return an "X" value in the BD?

Asked

Viewed 59 times

0

How do I not return an "X" value in the database?
For example, I have a site style Firefly, and the same has the page of each artist where is the tab "Related Artists" which is based on the TAGS registered in the comic, I wanted not return the value of the artist of the current page.

inserir a descrição da imagem aqui

  • Edit the post with the code to explain the doubt better please.

2 answers

5

If you refer to SQL, just use for example:

SELECT * FROM tabela_artistas WHERE id_artista <> id_artista_atual

3


You can do it in 2 ways:

Simple, filtering 1 record:

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

Example of the expected query result:

SELECT * FROM tb_artistas WHERE id <> 27

or if you bring more than 1 record, separating by comma:

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

Example of the expected query result:

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

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

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

Example of the expected query result:

SELECT * FROM tb_artistas WHERE id <> $id AND tag IN (2,5,8,10)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.