B
B
Bobur Bakhritdinov2015-12-13 18:54:29
PHP
Bobur Bakhritdinov, 2015-12-13 18:54:29

Arrays in php how to solve the problem?

Hi friends, help me solve one problem. There is a mysql database and a genre column
37fec2e0a6e947ba9516f527a7faf69a.jpg
As you can see, in one column there are genres separated by vergule.
When I make selections from the database and form a query into arrays, it forms the entire column for one identifier
fed8fafee45549b2a8f4fff2db31f97c.jpg
How to make each genre have its own identifier
Here is the source code:

$query  = "SELECT  *  FROM torrents";
$sql = $db->query($query);		   
$arr  = $db->get_row($sql) 

$genre = $arr['genre'];
print_r(array($genre));

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
D', 2015-12-13
@bakhritdinov_b

1) Normalize the table
2) Use substring_index, and crutches
3) Do the breakdown already in PHP, after the selection. ( $genre = explode(',', $arr['genre']); )
Choose any of the options.
PS
vergole = comma?

R
Rsa97, 2015-12-13
@Rsa97

If you just want to split the string then explode()
If you need a normal search by genre, normalize the database, put the genres in a separate linked table.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question