php - Cannot Use a Scalar Value as an Array, But Data Successfully Updated -


i have code :

public function updatesegmentgender ($product_id, $segment_gender) {      $this->connect();     $product_id = $this->escapestring($product_id);      $row_count = count($segment_gender);      ($row = 0; $row < $row_count; $row++) {          $this->select('product_seg_gender', '*', null,                        'product_id = "'.$product_id.'" , gender = "'.$segment_gender[$row][0].'"', null, null);         $res = $this->getresult();         $res = count($res);          $gender = $segment_gender[$row][0];         $status = $segment_gender[$row][1];          if ($res <> 0) {             // update             $data = array ('status'=>$status);             $this->update('product_seg_gender', $data, 'product_id = "'.$product_id.'" , gender = "'.$gender.'"');         }else {             // insert             $data = array ('product_id'=>$product_id, 'gender'=>$gender, 'status'=>$status);             $this->insert('product_seg_gender', $data);         }     } } 

and i'm using method :

$user = new product($db_server, $db_user, $db_password, $db_name); $user->connect();  $segment_gender = array ( array ("all", "active"),                           array ("female", "active"));  $res = $user->updatesegmentgender ('303', $segment_gender); print_r($res); 

but why got error message :

warning: cannot use scalar value array in /home/***/public_html/class/database.class.php on line 130 

however, database updated. did wrong?

update : here's complete line 97-145 of database.class.php

// function select database public function select($table, $rows = '*', $join = null, $where = null, $order = null, $limit = null){     // create query variables passed function     $q = 'select '.$rows.' '.$table;     if($join != null){         $q .= ' join '.$join;     }     if($where != null){         $q .= ' '.$where;     }     if($order != null){         $q .= ' order '.$order;     }     if($limit != null){         $q .= ' limit '.$limit;     }     // echo $table;     $this->myquery = $q; // pass sql     // check see if table exists     if($this->tableexists($table)){         // table exists, run query         $query = $this->myconn->query($q);             if($query){             // if query returns >= 1 assign number of rows numresults             $this->numresults = $query->num_rows;             // loop through query results number of rows returned             for($i = 0; $i < $this->numresults; $i++){                 $r = $query->fetch_array();                 $key = array_keys($r);                 for($x = 0; $x < count($key); $x++){                     // sanitizes keys alphavalues allowed                     if(!is_int($key[$x])){                         if($query->num_rows >= 1){                             $this->result[$i][$key[$x]] = $r[$key[$x]];                         }else{                             $this->result[$i][$key[$x]] = null;                         }                     }                 }             }             return true; // query successful         }else{             array_push($this->result,$this->myconn->error);             return false; // no rows returned         }     }else{         return false; // table not exist     } } 

note: hope require $res = $user->updatesegmentgender ('303', $segment_gender); need $data value , based on assumption use $data return part.

perhaps due $data not initialized. i'm trying declaring variable $data, array, before using make change function updatesegmentgender() require return part put this.

public function updatesegmentgender ($product_id, $segment_gender) {      $this->connect();     $product_id = $this->escapestring($product_id);      $row_count = count($segment_gender);      $data = array();//initialize variable...     ($row = 0; $row < $row_count; $row++) {          $this->select('product_seg_gender', '*', null,                        'product_id = "'.$product_id.'" , gender = "'.$segment_gender[$row][0].'"', null, null);         $res = $this->getresult();         $res = count($res);          $gender = $segment_gender[$row][0];         $status = $segment_gender[$row][1];          if ($res <> 0) {             // update             $data = array ('status'=>$status);             $this->update('product_seg_gender', $data, 'product_id = "'.$product_id.'" , gender = "'.$gender.'"');         }else {             // insert             $data = array ('product_id'=>$product_id, 'gender'=>$gender, 'status'=>$status);             $this->insert('product_seg_gender', $data);         }     }     //return funal value in array format...     return $data; } 

Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -