reference/mysqli/mysqli_result/data-seek.xml
035c126c0393fe154bac46e2c3c489ebadce48a5
...
...
@@ -4,18 +4,17 @@
4
4
<refnamediv>
5
5
<refname>mysqli_result::data_seek</refname>
6
6
<refname>mysqli_data_seek</refname>
7
-
<refpurpose>Adjusts the result pointer to an arbitary row in the result</refpurpose>
7
+
<refpurpose>Adjusts the result pointer to an arbitrary row in the result</refpurpose>
8
8
</refnamediv>
9
9

10
10
<refsect1 role="description">
11
11
&reftitle.description;
12
-
<para>Object oriented style (method):</para>
13
-
<methodsynopsis>
14
-
<type>bool</type><methodname>mysqli_result::data_seek</methodname>
12
+
<para>&style.oop;</para>
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
-

18
-
<para>Procedural style:</para>
17
+
<para>&style.procedural;</para>
19
18
<methodsynopsis>
20
19
<type>bool</type><methodname>mysqli_data_seek</methodname>
21
20
<methodparam><type>mysqli_result</type><parameter>result</parameter></methodparam>
...
...
@@ -37,7 +36,7 @@
37
36
<term><parameter>offset</parameter></term>
38
37
<listitem>
39
38
<para>
40
-
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
41
40
minus one (0..<function>mysqli_num_rows</function> - 1).
42
41
</para>
43
42
</listitem>
...
...
@@ -53,96 +52,122 @@
53
52
</para>
54
53
</refsect1>
55
54

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

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

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

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

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

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

92
-
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
93
83

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

87
+
$query = "SELECT Name, CountryCode FROM City ORDER BY Name";
88
+

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

98
-
/* close connection */
99
-
$mysqli->close();
100
-
?>
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]);
101
98
]]>
102
-
</programlisting>
99
+
</programlisting>
100
+
&examples.outputs;
101
+
<screen>
102
+
<![CDATA[
103
+
City: Benin City Countrycode: NGA
104
+
]]>
105
+
</screen>
103
106
</example>
107
+

104
108
<example>
105
-
<title>Procedural style</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>
106
114
<programlisting role="php">
107
115
<![CDATA[
108
116
<?php
109
-
/* Open a connection */
110
-
$link = mysqli_connect("localhost", "my_user", "my_password", "world");
111
117

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

118
-
$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);
119
123

120
-
if ($result = mysqli_query($link, $query)) {
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);
121
127

122
-
/* seek to row no. 400 */
123
-
mysqli_data_seek($result, 399);
128
+
/* Fetch single row */
129
+
$row = $result->fetch_row();
124
130

125
-
/* fetch row */
126
-
$row = mysqli_fetch_row($result);
131
+
printf("City: %s Countrycode: %s\n", $row[0], $row[1]);
132
+
}
127
133

128
-
printf ("City: %s Countrycode: %s\n", $row[0], $row[1]);
134
+
/* Reset pointer to the beginning of the result set */
135
+
$result->data_seek(0);
129
136

130
-
/* free result set*/
131
-
mysqli_free_result($result);
132
-
}
137
+
print "\n";
133
138

134
-
/* close connection */
135
-
mysqli_close($link);
136
-
?>
139
+
/* Iterate the same result set again */
140
+
while ($row = $result->fetch_row()) {
141
+
printf("City: %s Countrycode: %s\n", $row[0], $row[1]);
142
+
}
137
143
]]>
138
144
</programlisting>
139
-
</example>
140
-
&example.outputs;
141
-
<screen>
145
+
&examples.outputs;
146
+
<screen>
142
147
<![CDATA[
143
-
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
144
157
]]>
145
-
</screen>
158
+
</screen>
159
+
</example>
160
+
</refsect1>
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>
146
171
</refsect1>
147
172
148
173
<refsect1 role="seealso">
...
...
@@ -161,7 +186,6 @@ City: Benin City Countrycode: NGA
161
186
</refsect1>
162
187

163
188
</refentry>
164
-

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