Bonjour,
Je souhaite exploiter la classe Iterator et j'ai des soucis.
Je trouve bien le 1er puis le suivant (càd le 2ième et puis c'est tout)
Je trouve aussi le dernier (quoique ce ne soit prévu dans la classe originale) et le précédent le N-1 mais pas le N-2.....
Cela fait depuis ce matin tôt que je suis sur le pb, maintenant je le soumets à votre perspicasité !
Je ne mets pas le code de la forme ou l'HTML, c'est sans importance, sachez juste que les évents First/Next/Prev/Last sont des boutons interceptés par $_POST !
J'ai vérifié les résultas des "mysql_data_seek', ils sont === TRUE !
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89 <?php class MYsqlCursor implements Iterator { private $result, $position, $row_data, $numrows ; public function __construct () { $sql = "SELECT * FROM SCREEN"; $db = new MySQL(true /*utf8*/ , false /* debug */); $this->result = $db->query($sql); $this->position = 0; $this->numrows = mysql_affected_rows() - 1; } public function rewind ($offset=0) // First or anu other specified position { $this->position = $offset ; mysql_data_seek($this->result, $this->position); /* The initial call to valid requires that data pre-exists in $this->row_data */ return($this->current()); } public function first() { $this->position = 0 ; mysql_data_seek($this->result, $this->position); return($this->current()); } public function next() { if ($this->position + 1 < $this->numrows) mysql_data_seek($this->result, ++$this->position); return($this->current()); } public function prev() { if ($this->position - 1 > 0) mysql_data_seek($this->result, --$this->position); return($this->current()); } public function last() { $this->position = $this->numrows; mysql_data_seek($this->result, $this->position); return($this->current()); } // ----------------------------------------------------------------------------- public function current() { return( $this->row_data = mysql_fetch_assoc($this->result) ) ; } public function key() { return $this->position; } public function valid () { return (boolean) $this->row_data; } public function status() { return(" [".$this->position. "/".$this->numrows. "]") ; } } ?> <!-- ============================================================================================================================ --> <!-- === Body. === --> <!-- ============================================================================================================================ --> <?php $MYCursor = new MYsqlCursor() ; if (isset($_POST["First"])) { $Cursor = $MYCursor->first() ; print_r($Cursor) ; } if (isset($_POST["Next"])) { $Cursor = $MYCursor->next() ; print_r($Cursor) ; } if (isset($_POST["Prev"])) { $Cursor = $MYCursor->prev() ; print_r($Cursor) ; } if (isset($_POST["Last"])) { $Cursor = $MYCursor->last() ; print_r($Cursor) ; } ?>
Je n'ai rien dans le log PHP et je peux réitèrer ces mêmes tests "advitam eternam"....
Merci pour tout![]()
Partager