'v01', 'f2' => 'v02'), array('f1' => 'v11', 'f2' => 'v12'), array('f1' => 'v21', 'f2' => 'v22') ); $rs = new recordset($d); while ($rs->fetch()) { echo $rs->f('f1').' - '.$rs->f('f2').'
'; } ?> }}} @param array data Tableau contenant les données */ function recordset($data) { $this->int_index = 0; $this->fetch_index = NULL; if(is_array($data)) { $this->arry_data = $data; $this->int_row_count = count($this->arry_data); if ($this->int_row_count == 0) { $this->int_col_count = 0; } else { $this->int_col_count = count($this->arry_data[0]); } } } /** @function field Renvoie la valeur d'un champ donné, pour la ligne courante. @param mixed c Nom ou numéro du champ @return string */ function field($c) { if(!empty($this->arry_data)) { if(is_integer($c)) { $T = array_values($this->arry_data[$this->int_index]); return (isset($T[($c)])) ? $T[($c)] : false; } else { $c = strtolower($c); if(isset($this->arry_data[$this->int_index][$c])) { if (!is_array($this->arry_data[$this->int_index][$c])) { return trim($this->arry_data[$this->int_index][$c]); } else { return $this->arry_data[$this->int_index][$c]; } } else { return false; } } } } /** @function f Alias de la méthode ''field''. @param mixed c Nom ou numéro du champ @return string */ function f($c) { return $this->field($c); } /** @function setField Change la valeur d'un champ donné à la ligne courante. @param string c Nom du champ @param string v Valeur du champ */ function setField($c,$v) { $c = strtolower($c); $this->arry_data[$this->int_index][$c] = $v; } /** @function moveStart Remet le curseur à la première ligne des données et renvoie vrai. @return boolean */ function moveStart() { $this->int_index = 0; return true; } /** @function moveEnd Positionne le curseur à la dernière ligne des données et renvoie vrai. @return boolean */ function moveEnd() { $this->int_index = ($this->int_row_count-1); return true; } /** @function moveNext Déplace le curseur d'un cran si possible et renvoie vrai. Si le curseur est à la fin du tableau, renvoie false. @return boolean */ function moveNext() { if (!empty($this->arry_data) && !$this->EOF()) { $this->int_index++; return true; } else { return false; } } /** @function movePrev Déplace le curseur d'un cran dans le sens inverse si possible et renvoie vrai. Si le curseur est au début du tableau, renvoie false. @return boolean */ function movePrev() { if (!empty($this->arry_data) && $this->int_index > 0) { $this->int_index--; return true; } else { return false; } } /** @function move Positionne le curseur à l'indice donné par $index. Si l'indice n'existe pas, renvoie false. @param integer index Indice @return boolean */ function move($index) { if (!empty($this->arry_data) && $this->int_index >= 0 && $index < $this->int_row_count) { $this->int_index = $index; return true; } else { return false; } } /** @function fetch Déplace le cuseur d'un cran et renvoie vrai tant que celui ci n'est pas positionné à la fin du tableau. La fonction démarre toujours du premier élément du tableau. Elle a pour vocation à être utilisée dans une boucle de type while (voir le premier exemple). @return boolean */ function fetch() { if ($this->fetch_index === NULL) { $this->fetch_index = 0; $this->int_index = -1; } if ($this->fetch_index+1 > $this->int_row_count) { $this->fetch_index = NULL; $this->int_index = 0; return false; } $this->fetch_index++; $this->int_index++; return true; } /** @function BOF Indique si le curseur est au début du tableau. @return boolean */ function BOF() { return ($this->int_index == -1 || $this->int_row_count == 0); } /** @function EOF Indique si le curseur est à la fin du tableau. @return boolean */ function EOF() { return ($this->int_index == $this->int_row_count); } /** @function isEmpty Indique si le tableau de données est vide. @return boolean */ function isEmpty() { return ($this->int_row_count == 0); } /** @function getData Renvoie le tableau de données. @return array */ function getData() { return $this->arry_data; } /** @function nbRow Renvoie le nombre de lignes du tableau. @return integer */ function nbRow() { return $this->int_row_count; } } ?>