you need to get a row with data from the Group table and replace them with, for example [3] - [2], the first values ​​in square brackets means that you need to take the row with the data 'tractor' from the List 3 table and another value from the Brand table John Dear and these value put in two different variables

tractor - john deere

car - audi

motorcycle - ducati

database structure:

List |---------|----------| | list_id | title | |---------|----------| | 1 | машина | |---------|----------| | 2 | ΠΌΠΎΡ‚ΠΎΡ†ΠΈΠΊΠ» | |---------|----------| | 3 | Ρ‚Ρ€Π°ΠΊΡ‚ΠΎΡ€ | |---------|----------| Brand |---------|----------| |brand_id | title | |---------|----------| | 1 | Π°ΡƒΠ΄ΠΈ | |---------|----------| | 2 | Π΄ΠΆΠΎΠ½ Π΄ΠΈΡ€ | |---------|----------| | 3 | Π΄ΡƒΠΊΠ°Ρ‚ΠΈ | |---------|----------| Group |----------|-------------------| | Group_id | text | |----------|-------------------| | 1 | [4]-[23], | | | [9]-[3] | |----------|-------------------| | 2 | [2]-[37], | | | [8]-[41], | | | [11]-[24], | | | [2]-[15] | |----------|-------------------| 

Code

 def my_db(): conn = sqlite3.connect('db.sqlite') c = conn.cursor() c.execute('SELECT * FROM List WHERE list_id = 1') row = c.fetchone() # Π·Π°ΠΊΡ€Ρ‹Π²Π°Π΅ΠΌ соСдинСниС с Π±Π°Π·ΠΎΠΉ c.close() conn.close() return row 
  • one
    nothing is clear without table structures. but apparently you are asking about join - splash58
  • the structure is composed of two tables List and Brand - Kill Noise
  • With such a terrible structure of the text field, you can probably write a request, but it is easier to parse it in a programming language, make an id list, get from the database by the where-in criterion (id list) and make a substitution - splash58
  • please show code examples - Kill Noise
  • The fact is that I do not know how to python. I can tell the logic, but to write the code is weak :) Maybe. who knows how to tell. But the code is not often written here, it would be right for you to try and address with problems - splash58

1 answer 1

 $text = '[2]-[37], [8]-[41], [11]-[24], [2]-[15]'; $arr = array_map(trim, explode(',',$text)); $arr = array_map(function($i) { $i = array_map(function ($j) { return trim($j, "[]"); }, explode('-', $i)); return $i; }, $arr); print_r($arr); 

as a result there will be such an array

 [ [2, 37], [8, 41], [11, 24], [2, 15] ] 

now collect zero indexes and make a query to the List with where list_id in (list) and with elements with index = 1 to the second table. And then just make a conclusion