denormalized

unserialize() value of database and putting it in json_encode after foreach

╄→гoц情女王★ 提交于 2019-12-02 17:47:20
问题 I insert in database values (array) $row->units with use function serialize() => [$row->units] , how can echo they with unserialize() in json_encode with $row->name ? (return send for ajax call in jQuery) Columns in database: $row->units => a:6:{i:0;s:15:"Coffee";i:1;s:14:"Satellite";i:2;s:11:"Game Notes";i:3;s:14:"Internet";i:4;s:10:"Pool";i:5;s:0:"";} $row->name=> George Kurdahi $query = $this->db->query("SELECT * FROM arraha WHERE name LIKE '%$search%' ORDER BY name asc"); $data = array();

unserialize() value of database and putting it in json_encode after foreach

冷暖自知 提交于 2019-12-02 10:15:19
I insert in database values (array) $row->units with use function serialize() => [$row->units] , how can echo they with unserialize() in json_encode with $row->name ? (return send for ajax call in jQuery) Columns in database: $row->units => a:6:{i:0;s:15:"Coffee";i:1;s:14:"Satellite";i:2;s:11:"Game Notes";i:3;s:14:"Internet";i:4;s:10:"Pool";i:5;s:0:"";} $row->name=> George Kurdahi $query = $this->db->query("SELECT * FROM arraha WHERE name LIKE '%$search%' ORDER BY name asc"); $data = array(); foreach ($query->result() as $row) { $data[] = array('name' => $row->name, 'units' => unserialize($row

Oracle SQL getting the nth element regexp

佐手、 提交于 2019-12-01 05:07:07
I am trying to get the nth element in a comma separated string using SQL in Oracle. I have the following so far.. SELECT regexp_substr( '100016154,5101884LT00001,,,,,100000010892100000012655,L,SEI,5101884LT00001,1,SL,3595.03,00,2,N,N,G,N', '[^,]+', 1, 7) FROM dual; but it doesn't work when the element is empty i.e. ,, can anyone help? If your delimited values are always alphanumeric in between the commas then you could try: SELECT REGEXP_SUBSTR( <delimied_string>, '[[:alnum:]]{0,},', 1, 7 ) FROM dual; To get the seventh value (including the trailing comma). If it is empty you just get the

Join tables with comma values

北慕城南 提交于 2019-11-28 14:40:00
I have a hard nut to crack with joing 3 tables. I have a newsletter_items, newsletter_fields and newsletter_mailgroups which I want to be joined to get a list of newsletters. The newsletter_items contains the fields: letter_id, letter_date, receivers, template, status That can look like 1, 1234567899, 1,2 (comma separated), standard.html, 1 newsletter_fields contains the fields: field_uid, field_name, field_content, field_letter_uid That can look like 1, letter_headline, A great headline, 1 where field_letter_uid is the newsletter for which the field belongs to. and newsletter_mailgroups

Mysql WHERE problem with comma-separated list

£可爱£侵袭症+ 提交于 2019-11-28 13:47:45
I need help for this problem. In MYSQL Table i have a field : Field : artist_list Values : 1,5,3,401 I need to find all records for artist uid 401 I do this SELECT uid FROM tbl WHERE artist_list IN ('401'); I have all record where artist_list fields values are '401' only, but if i have 11,401 this query do not match. Any idea ? (I cant user LIKE method because if artist uid is 3 (match for 30, 33, 3333)... Short Term Solution Use the FIND_IN_SET function : SELECT uid FROM tbl WHERE FIND_IN_SET('401', artist_list) > 0 Long Term Solution Normalize your data - this appears to be a many-to-many

Join tables with comma values

南笙酒味 提交于 2019-11-27 08:44:29
问题 I have a hard nut to crack with joing 3 tables. I have a newsletter_items, newsletter_fields and newsletter_mailgroups which I want to be joined to get a list of newsletters. The newsletter_items contains the fields: letter_id, letter_date, receivers, template, status That can look like 1, 1234567899, 1,2 (comma separated), standard.html, 1 newsletter_fields contains the fields: field_uid, field_name, field_content, field_letter_uid That can look like 1, letter_headline, A great headline, 1

Mysql WHERE problem with comma-separated list

╄→尐↘猪︶ㄣ 提交于 2019-11-27 07:53:48
问题 I need help for this problem. In MYSQL Table i have a field : Field : artist_list Values : 1,5,3,401 I need to find all records for artist uid 401 I do this SELECT uid FROM tbl WHERE artist_list IN ('401'); I have all record where artist_list fields values are '401' only, but if i have 11,401 this query do not match. Any idea ? (I cant user LIKE method because if artist uid is 3 (match for 30, 33, 3333)... 回答1: Short Term Solution Use the FIND_IN_SET function: SELECT uid FROM tbl WHERE FIND

Storing arrays in the database

丶灬走出姿态 提交于 2019-11-26 22:51:52
I'm wondering if it is actually good practise to store Arrays in the database ? I tend to use json_encode rather than serialize , but was just wondering if it is a good idea. If not, then I can make some small changes and just implode the array with a comma. No, it's a terrible practice. Please refrain from inserting CSV, JSON*, serialize() or ANY kind of serialized data in a relational database. Denormalization is almost always a bad idea - don't do it unless you really know what you are doing, or you'll start asking questions like: this , this , this , this , ... Doing that, you lose or it

Is it possible to query a comma separated column for a specific value?

[亡魂溺海] 提交于 2019-11-26 17:58:07
I have (and don't own, so I can't change) a table with a layout similar to this. ID | CATEGORIES --------------- 1 | c1 2 | c2,c3 3 | c3,c2 4 | c3 5 | c4,c8,c5,c100 I need to return the rows that contain a specific category id. I starting by writing the queries with LIKE statements, because the values can be anywhere in the string SELECT id FROM table WHERE categories LIKE '%c2%'; Would return rows 2 and 3 SELECT id FROM table WHERE categories LIKE '%c3%' and categories LIKE '%c2%'; Would again get me rows 2 and 3, but not row 4 SELECT id FROM table WHERE categories LIKE '%c3%' or categories

Storing arrays in the database

早过忘川 提交于 2019-11-26 08:29:34
问题 I\'m wondering if it is actually good practise to store Arrays in the database ? I tend to use json_encode rather than serialize , but was just wondering if it is a good idea. If not, then I can make some small changes and just implode the array with a comma. 回答1: No, it's a terrible practice. Please refrain from inserting CSV, JSON*, serialize() or ANY kind of serialized data in a relational database. Denormalization is almost always a bad idea - don't do it unless you really know what you