note 89427 added to function.array-slice
| From: | uncleneg at yahoo dot com | Date: | Sat, 07 Mar 2009 14:08:07 +0000 |
| Subject: | note 89427 added to function.array-slice | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-151589@lists.php.net to get a copy of this message | ||
You should regard this!: FOR EXAMPLE:
$result is a simple SQL table
with Fieldname1, Fieldname2, Fieldname3
and values in first row 'val1', 'val2', 'val3':
Case 1:
$row=$mysqli_fetch_row($result,MYSQL_NUM);
$mystring=implode('',array_slice($row,0,3));
echo $mystring; //will be: 'val1val2val3' this is OK.
Case 2: Only you are changing MYSQL_NUM to MYSQL_BOTH:
$row=$mysqli_fetch_row($result,MYSQL_BOTH);
$mystring=implode('',array_slice($row,0,3));
echo $mystring; //will be: 'val1val1val2' this can be a big problem!
Explain:
In Case2 $row will be:
$row = {
[0] => 'val1'
[Fieldname1] => 'val1'
[1] => 'val2'
[Fieldname2] => 'val2'
[2] => 'val3'
[Fieldname3] => 'val3'
}
then array_slice will also collect Array Keys Fieldname1..3 with 0..2 one after the other
unfortunately.
My opinion:
If $row would be the following after a mysql_fetch:
$row = {
[0] => 'val1'
[1] => 'val2'
[2] => 'val3'
[Fieldname1] => 'val1'
[Fieldname2] => 'val2'
[Fieldname3] => 'val3'
}
then this problem doesn't happen. :)
----
Server IP: 92.43.200.200
Probable Submitter: 88.209.235.51
----
Manual Page -- http://www.php.net/manual/en/function.array-slice.php
Edit -- https://master.php.net/note/edit/89427
Del: integrated -- https://master.php.net/note/delete/89427/integrated
Del: useless -- https://master.php.net/note/delete/89427/useless
Del: bad code -- https://master.php.net/note/delete/89427/bad+code
Del: spam -- https://master.php.net/note/delete/89427/spam
Del: non-english -- https://master.php.net/note/delete/89427/non-english
Del: in docs -- https://master.php.net/note/delete/89427/in+docs
Del: other reasons-- https://master.php.net/note/delete/89427
Reject -- https://master.php.net/note/reject/89427
Search -- https://master.php.net/manage/user-notes.php