Page 1 of 1

หนู foreach INSERT ไม่เข้า T^T

Posted: 22/10/2014 5:56 pm
by thatsawan

Code: Select all

if (sizeof($add_groups)){ 
                                foreach ($add_groups as $group => $user_data) {
                                        foreach ($user_data as $id) {
                                        $sql = " SELECT COUNT(*)  FROM ".USER_GROUP_TABLE ." WHERE user_id= ".$id." AND group_id = " .$group ;
                                        $result = $db->sql_query($sql);
                                        $user_group = $db->sql_fetchrow($result);
                                        $sum = $user_group['COUNT(*)'];
                                        if($sum  == 0){
                                                $sql_a = 'INSERT INTO ' . USER_GROUP_TABLE . ' ' . $db->sql_build_array('INSERT', array(
                                                        'user_id'        => $id,
                                                        'group_id'        => (int) $group,
                                                        'user_pending'    => 0
                                                ));
                                               // exit($sql_a);
                                                $db->sql_query($sql_a);
                                                }
                                        }  
                                }
                        } 
INSERT INTO phpbb_user_group (user_id, group_id, user_pending) VALUES (54, 8, 0)

Re: หนู INSERT ไม่เข้า T^T

Posted: 22/10/2014 6:14 pm
by thatsawan
ใส่แบบนี้เข้านะ

Code: Select all

$db->sql_query($sql_a);
exit();