Hi guys, I'm wondering if there's any regx ninja that can solve my problem. 1.QUERY. $query = 'UPDATE tbl_class SET class_status = 3 WHERE class_id = 4 AND class_status = 2'; From the above query, I want to grab only the "class_status = 2" part and also the "class_id = 4" part. 2.QUERY $query = 'INSERT INTO tbl_stud_class(class_id, stud_id) VALUES(1, 3)'; From the above query, I want to grab only the 'class_id' and 'class_id values 1' part, I also want to grab the 'stud_id' and 'stud_id values 3' part To be more clear. I want the result in a array like $match = array('class_id' => 1, 'stud_id' => 3); PHP: Your help will appriciated. Thanks.
I like to help you, but to tell true I cant understand what you are trying for. You are updating and inserting data to table and you say you need to grab certain details in an array .. that is not possible ... Are you trying to execute a query which will " select " the details you need as in array ?
Hi, Can you be a little bit specific: I mean if you provide tables structure (as create table scripts; no pictures please ) with few lines data in them an desired result set, I'm almost sure you don't need regexp here. Regards p.p.: How to grab data via Insert?
Hi I'm not trying to insert something to the database. I want to use the preg_match (regex pattern) to grab a parts of string from a query.
ok, maybe this: $s='INSERT INTO tbl_stud_class(class_id, stud_id) VALUES(1, 3)'; $arr=array(); preg_match_all('#\(([^\),]+),([^\),]+)\)#ius',$s,&$arr); //print_r($arr); you can uncomment if (count($arr[1])) echo implode(' ',$arr[1])."\r\n"; if (count($arr[2])) echo implode(' ',$arr[2])."\r\n"; PHP: