Welcome Guest, Not a member yet? Register   Sign In
cleared: one FOREACH works - other one not. Do you see why?
#1

[eluser]Jan_1[/eluser]
Trying to display how many fields in userprofil and in groupprofil are filled.
First one works. Second doesn't. Error-Message is "array_values(): The argument should be an array" and "Invalid argument supplied for foreach()"

Could you please have a look? Thank you!!!

This one works:
Code:
$query = $this->db->query('SELECT * FROM user_profile');
      $number_allpfields = $query->num_fields();

      $this->db->where('id', $user_id);
      $query = $this->db->get('user_profile');
      if ($query->num_rows() > 0) { $row = $query->row_array();}
      $i = 0; FOREACH (array_values($row) as $item) {$i++;} $i--;
      $number_fullpfields = $i;
      $profilstatus = $number_fullpfields / $number_allpfields;
      echo $profilstatus;                                        // ok!

This one does not work:
Code:
$query = $this->db->get('group_profil');
      $number_allfields = $query->num_fields();
      echo $number_allfields."<br>";                             //ok!
      
      $this->db->where('id', $group_id);
      $query = $this->db->get('group_profil');
      if ($query->num_rows() > 0) { $row = $query->row_array(); }
      print_r($row);                                              // ok!

      $i = 0;
      FOREACH (array_values($row) as $item) {$i++;}   //<-- error !//
      $i--;
      $number_fullfields = $i;
      $status = $number_fullfields / $number_allfields;
      echo $status;
#2

[eluser]Jan_1[/eluser]
Could not work if it does not get a valid id. :red:




Theme © iAndrew 2016 - Forum software by © MyBB