note 89257 added to function.array-slice
| From: | uncleneg at yahoo dot com | Date: | Sat, 28 Feb 2009 14:52:19 +0000 |
| Subject: | note 89257 added to function.array-slice | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-151247@lists.php.net to get a copy of this message | ||
THIS IS A BIG SUCK!: 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: 62.112.195.86
Probable Submitter: 88.209.239.28
----
Manual Page -- http://www.php.net/manual/en/function.array-slice.php
Edit -- https://master.php.net/note/edit/89257
Del: integrated -- https://master.php.net/note/delete/89257/integrated
Del: useless -- https://master.php.net/note/delete/89257/useless
Del: bad code -- https://master.php.net/note/delete/89257/bad+code
Del: spam -- https://master.php.net/note/delete/89257/spam
Del: non-english -- https://master.php.net/note/delete/89257/non-english
Del: in docs -- https://master.php.net/note/delete/89257/in+docs
Del: other reasons-- https://master.php.net/note/delete/89257
Reject -- https://master.php.net/note/reject/89257
Search -- https://master.php.net/manage/user-notes.php