reference/mysqli/mysqli_result/data-seek.xml
035c126c0393fe154bac46e2c3c489ebadce48a5
...
...
@@ -10,8 +10,8 @@
10
10
<refsect1 role="description">
11
11
&reftitle.description;
12
12
<para>&style.oop;</para>
13
-
<methodsynopsis role="oop">
14
-
<type>bool</type><methodname>mysqli_result::data_seek</methodname>
13
+
<methodsynopsis role="mysqli_result">
14
+
<modifier>public</modifier> <type>bool</type><methodname>mysqli_result::data_seek</methodname>
15
15
<methodparam><type>int</type><parameter>offset</parameter></methodparam>
16
16
</methodsynopsis>
17
17
<para>&style.procedural;</para>
...
...
@@ -36,7 +36,7 @@
36
36
<term><parameter>offset</parameter></term>
37
37
<listitem>
38
38
<para>
39
-
The field offset. Must be between zero and the total number of rows
39
+
The row offset. Must be between zero and the total number of rows
40
40
minus one (0..<function>mysqli_num_rows</function> - 1).
41
41
</para>
42
42
</listitem>
...
...
@@ -52,98 +52,124 @@
52
52
</para>
53
53
</refsect1>
54
54

55
-
<refsect1 role="notes">
56
-
&reftitle.notes;
57
-
<note>
58
-
<para>
59
-
This function can only be used with buffered results attained from the
60
-
use of the <function>mysqli_store_result</function> or
61
-
<function>mysqli_query</function> functions.
62
-
</para>
63
-
</note>
64
-
</refsect1>
65
-

66
55
<refsect1 role="examples">
67
56
&reftitle.examples;
68
57
<example>
69
-
<title>&style.oop;</title>
58
+
<title><methodname>mysqli::data_seek</methodname> example</title>
59
+
<para>&style.oop;</para>
70
60
<programlisting role="php">
71
61
<![CDATA[
72
62
<?php
73
-
/* Open a connection */
74
-
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
75
63

76
-
/* check connection */
77
-
if (mysqli_connect_errno()) {
78
-
printf("Connect failed: %s\n", mysqli_connect_error());
79
-
exit();
80
-
}
64
+
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
65
+
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
81
66

82
67
$query = "SELECT Name, CountryCode FROM City ORDER BY Name";
83
-
if ($result = $mysqli->query($query)) {
68
+
$result = $mysqli->query($query);
84
69

85
-
/* seek to row no. 400 */
86
-
$result->data_seek(399);
70
+
/* Seek to row no. 401 */
71
+
$result->data_seek(400);
87
72

88
-
/* fetch row */
89
-
$row = $result->fetch_row();
73
+
/* Fetch single row */
74
+
$row = $result->fetch_row();
90
75

91
-
printf ("City: %s Countrycode: %s\n", $row[0], $row[1]);
76
+
printf("City: %s Countrycode: %s\n", $row[0], $row[1]);
77
+
]]>
78
+
</programlisting>
79
+
<para>&style.procedural;</para>
80
+
<programlisting role="php">
81
+
<![CDATA[
82
+
<?php
92
83

93
-
/* free result set*/
94
-
$result->close();
95
-
}
84
+
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
85
+
$link = mysqli_connect("localhost", "my_user", "my_password", "world");
96
86

97
-
/* close connection */
98
-
$mysqli->close();
99
-
?>
87
+
$query = "SELECT Name, CountryCode FROM City ORDER BY Name";
88
+

89
+
$result = mysqli_query($link, $query);
90
+

91
+
/* Seek to row no. 401 */
92
+
mysqli_data_seek($result, 400);
93
+

94
+
/* Fetch single row */
95
+
$row = mysqli_fetch_row($result);
96
+

97
+
printf ("City: %s Countrycode: %s\n", $row[0], $row[1]);
100
98
]]>
101
99
</programlisting>
100
+
&examples.outputs;
101
+
<screen>
102
+
<![CDATA[
103
+
City: Benin City Countrycode: NGA
104
+
]]>
105
+
</screen>
102
106
</example>
107
+

103
108
<example>
104
-
<title>&style.procedural;</title>
109
+
<title>Adjusting the result pointer when iterating</title>
110
+
<para>
111
+
This function can be useful when iterating over the result set to impose
112
+
a custom order or rewind the result set when iterating multiple times.
113
+
</para>
105
114
<programlisting role="php">
106
115
<![CDATA[
107
116
<?php
108
-
/* Open a connection */
109
-
$link = mysqli_connect("localhost", "my_user", "my_password", "world");
110
117

111
-
/* check connection */
112
-
if (!$link) {
113
-
printf("Connect failed: %s\n", mysqli_connect_error());
114
-
exit();
115
-
}
118
+
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
119
+
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
116
120

117
-
$query = "SELECT Name, CountryCode FROM City ORDER BY Name";
121
+
$query = "SELECT Name, CountryCode FROM City ORDER BY Name LIMIT 15,4";
122
+
$result = $mysqli->query($query);
123
+

124
+
/* Iterate the result set in reverse order */
125
+
for ($row_no = $result->num_rows - 1; $row_no >= 0; $row_no--) {
126
+
$result->data_seek($row_no);
118
127

119
-
if ($result = mysqli_query($link, $query)) {
128
+
/* Fetch single row */
129
+
$row = $result->fetch_row();
120
130

121
-
/* seek to row no. 400 */
122
-
mysqli_data_seek($result, 399);
131
+
printf("City: %s Countrycode: %s\n", $row[0], $row[1]);
132
+
}
123
133

124
-
/* fetch row */
125
-
$row = mysqli_fetch_row($result);
134
+
/* Reset pointer to the beginning of the result set */
135
+
$result->data_seek(0);
126
136

127
-
printf ("City: %s Countrycode: %s\n", $row[0], $row[1]);
137
+
print "\n";
128
138

129
-
/* free result set*/
130
-
mysqli_free_result($result);
139
+
/* Iterate the same result set again */
140
+
while ($row = $result->fetch_row()) {
141
+
printf("City: %s Countrycode: %s\n", $row[0], $row[1]);
131
142
}
132
-

133
-
/* close connection */
134
-
mysqli_close($link);
135
-
?>
136
143
]]>
137
144
</programlisting>
138
145
&examples.outputs;
139
146
<screen>
140
147
<![CDATA[
141
-
City: Benin City Countrycode: NGA
148
+
City: Acmbaro Countrycode: MEX
149
+
City: Abuja Countrycode: NGA
150
+
City: Abu Dhabi Countrycode: ARE
151
+
City: Abottabad Countrycode: PAK
152
+

153
+
City: Abottabad Countrycode: PAK
154
+
City: Abu Dhabi Countrycode: ARE
155
+
City: Abuja Countrycode: NGA
156
+
City: Acmbaro Countrycode: MEX
142
157
]]>
143
158
</screen>
144
159
</example>
145
160
</refsect1>
146
161

162
+
<refsect1 role="notes">
163
+
&reftitle.notes;
164
+
<note>
165
+
<para>
166
+
This function can only be used with buffered results attained from the
167
+
use of the <function>mysqli_store_result</function>,
168
+
<function>mysqli_query</function> or <function>mysqli_stmt_get_result</function> functions.
169
+
</para>
170
+
</note>
171
+
</refsect1>
172
+
147
173
<refsect1 role="seealso">
148
174
&reftitle.seealso;
149
175
<para>
...
...
@@ -160,7 +186,6 @@ City: Benin City Countrycode: NGA
160
186
</refsect1>
161
187

162
188
</refentry>
163
-

164
189
<!-- Keep this comment at the end of the file
165
190
Local variables:
166
191
mode: sgml
167
192