Read phpMyAdmin column with multiple records

Asked

Viewed 231 times

2

I have a table in phpMyAdmin with a field that stores several values, the column is named id_subfilter, I need to read each value of this, because the same are id s that are related to another table the field is a varchar.

The table is this, the field I need to read is what is marked, see:

inserir a descrição da imagem aqui

I couldn’t find anything related to the research I did.

  • You want to use these Ids to join with another table, that’s it?

  • That’s right @bfavaretto, I need to separate them to use in the relationship.

  • 2

    The good thing was not to have this multivariate column if you can’t turn it into a new table, maybe this answer can help: What syntax to search with array as parameter in Mysql?

2 answers

3

I recommend you do a better modeling of the bank, creating a relational table for this case.

For example, a table between equipment and workers both have an identifier ID, to properly relate to a cardinality N for N relationship, it would be good to create a table equipamentos_trabalhadores where there would be the id_equipamento and the id_trabalhor, this could relate N records, which can be accessed only by id_equipamento or id_trabalhor, thus making access easier and faster.

But if you want to continue with this modeling, you can bring all the data to the programming, or to the query, and use regular expression methods that their use varies depending on the desired programming language.

For using Phpmyadmin I imagine you should use PHP, so I will put a regular expression reference in PHP, but if not this function is available in all languages, follows reference:

http://www.devmedia.com.br/expressoes-regulares-em-php/25076

With this method one can pick up particles from a given text, thus being able to separate the ids who wishes, however, this way is not very suitable for this treatment.

  • 1

    If it is to solve in PHP, a explode would solve, nor need regex... But I agree with you that the correct is to model the bank in another way.

  • Yes, I don’t know much about PHP, I tried to pass a generic method

  • No problem, sorry to bother you...

  • On the contrary, thank you for your help

3


If the goal is to make a JOIN with another table, Mysql offers a shortcut which is the function FIND_IN_SET. But she has performance problems, the correct thing would be to model the bank in another way and use a relationship table, as already suggested in Alfredo Silveira’s response and rray comment.

For the record, follow an example of gambiarra with the FIND_IN_SET:

SELECT tabela1.*
FROM tabela1
    INNER JOIN tabela2
    ON FIND_IN_SET(tabela2.id, tabela1.id_subfiltro) > 0
  • 1

    Your POG solution has helped me very much my dear, thank you for your attention.

    • 1 for admitting to gambiarra kkkk

Browser other questions tagged

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