Jump to content

array in mysql database?


techker

Recommended Posts

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

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

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

odd cause no matter what i try i get an error like

 

SELECT * FROM `packages` WHERE  JSON_CONTAINS (groups , "4") ;

MySQL said: Documentation

#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

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 ..

Edited by techker
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.