techker Posted April 7, 2019 Share Posted April 7, 2019 Hey guys i have a database set up and im trying to figure out how to show and edit the content in a table that has ["http:\/\/streams.com:\/live\/A245\/23424\/6207.ts","http:\/\/streams\/live\/123\/43r3222\/27357.ts"] so when i eco this i get that? is this stored as an array? and why the \/ is that separate values? Link to comment Share on other sites More sharing options...
benanamen Posted April 7, 2019 Share Posted April 7, 2019 The \ is escaping the /. Why is your data in the DB like that in the first place? Link to comment Share on other sites More sharing options...
requinix Posted April 7, 2019 Share Posted April 7, 2019 It's JSON, by the way. If you're using MySQL 5.7+ and the JSON data type then it's okay, otherwise it's not very okay. Link to comment Share on other sites More sharing options...
techker Posted April 7, 2019 Author Share Posted April 7, 2019 that explains it ..json..hmm its the panel that was made like that..im just connecting to the backend of it .. ya the Mysql is the latest.. so how can i show that text in a way that we can modify and resave? Link to comment Share on other sites More sharing options...
requinix Posted April 7, 2019 Share Posted April 7, 2019 If you want to work with it in PHP then you need to decode/encode it. If you want to work with it in MySQL then use its JSON functions. Link to comment Share on other sites More sharing options...
techker Posted April 7, 2019 Author Share Posted April 7, 2019 interesting thx Link to comment Share on other sites More sharing options...
techker Posted April 8, 2019 Author Share Posted April 8, 2019 last question..maybe..lol sorry LEGEND: 1-admin 2 user ,3 user level 1 ,4 user level4 .... in my table i have a column groups with [1,2,4] how can i make a query to select the tables associated to groups [1] only cause i have some that i tried..also tried JSON_CONTAINS but the mysql error said does not exist? SELECT * FROM `packages` WHERE 2 IN (".implode(',','groups').")LIMIT 0 , 30 Link to comment Share on other sites More sharing options...
requinix Posted April 8, 2019 Share Posted April 8, 2019 What is the actual query you tried to run, as in whatever your PHP produced and not the code that you used to create it, and what was the error message? Link to comment Share on other sites More sharing options...
Barand Posted April 8, 2019 Share Posted April 8, 2019 Here's an example mysql> SELECT name, role FROM json_test; +-------+--------------+ | name | role | +-------+--------------+ | Peter | [1, 2, 3] | | Paul | [1, 3] | | Mary | [1, 2, 4] | | Jane | [2, 4] | | Fred | [1, 2, 3, 4] | +-------+--------------+ 5 rows in set (0.00 sec) mysql> SELECT name, role FROM json_test WHERE JSON_CONTAINS(role, "3"); +-------+--------------+ | name | role | +-------+--------------+ | Peter | [1, 2, 3] | | Paul | [1, 3] | | Fred | [1, 2, 3, 4] | +-------+--------------+ 3 rows in set (0.00 sec) Link to comment Share on other sites More sharing options...
techker Posted April 9, 2019 Author Share Posted April 9, 2019 odd cause no matter what i try i get an error like SELECT * FROM `packages` WHERE JSON_CONTAINS (groups , "4") ; MySQL said: #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 PHP/5.5.9-1ubuntu4.27 mysql 5.5.62 Link to comment Share on other sites More sharing options...
techker Posted April 9, 2019 Author Share Posted April 9, 2019 ok i found that just the simple loop works..lol $dataArray = json_decode($groups,true); foreach($dataArray as $key => $value){ echo $value; } Link to comment Share on other sites More sharing options...
Barand Posted April 9, 2019 Share Posted April 9, 2019 On 4/7/2019 at 4:07 AM, techker said: ya the Mysql is the latest.. 1 hour ago, techker said: mysql 5.5.62 One of those statements can't be true. (JSON functions require MySQL 5.7+) Link to comment Share on other sites More sharing options...
techker Posted April 12, 2019 Author Share Posted April 12, 2019 odd so how come it is inserted like that.. how can i make a function to edit this: "http:\/\/streams.com:\/live\/A245\/23424\/6207.ts","http:\/\/streams\/live\/123\/43r3222\/27357.ts"] guessing i need to remove the\/ and replace by // . and when i save i need to re add the \/ im messing around with SELECT streams_source REPLACE(streams_source,'\/','//') as output FROM Stream WHERE 1; but getting mysql errors .. Link to comment Share on other sites More sharing options...
techker Posted April 12, 2019 Author Share Posted April 12, 2019 Ok i think i got it.. $result= str_replace('\\', '', $stream_source); $result = str_replace("'", "", $result); //remove single quotes so i remove the \ all i need to do is reverse that to save Link to comment Share on other sites More sharing options...
requinix Posted April 12, 2019 Share Posted April 12, 2019 No. The backslashes are optional but okay. It does not matter if they are there. Do not try to manipulate the JSON string like that. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.