|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2001-10-15 18:45 UTC] jeroen@php.net
[2001-10-15 19:23 UTC] sniper@php.net
[2001-11-09 14:58 UTC] sander@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 07:00:01 2025 UTC |
Creating a mysql database that holds a field of values, e.g. TLDs, with row 0 containing cx nu com org net, row 1 containing it at de us com, and so forth, a semi-annoying bug can be created with array_unique() that will insert null elements into the new array. For example: <? $connection = mysql_connect("localhost","classicgames","classicgames"); mysql_select_db("classicgames",$connection); $query = "select votes from tldvote"; $result = mysql_query($query); $i = 0; while($row = mysql_fetch_row($result)) { $string = implode("",$row); $tempArray = explode(" ",$string); for($j = 0; $j < 5; $j++) { $votes[$i][$j] = $tempArray[$j]; } $i++; } for($i = 0, $k = 0; $i < sizeOf($votes); $i++) for($j = 0; $j < 5; $j++) { $type[$k] = $votes[$i][$j]; $k++; } /* Bug is created here, just this script alone will produce an array of unique types as well as null (more-so towards "") types. */ $tempType = array_unique($type); for($i = 0; $i < sizeOf($type); $i++) for($j = 0; $j < sizeOf($tempType); $j++) if($type[$i] == $tempType[$j]) $tally[$j] = $tally[$j] + 1; array_multisort($tally, SORT_DESC,$tempType); for ($i = 0; $i < sizeOf($tally); $i++) echo $tempType[$i]." has ".$tally[$i]." votes.<br>"; ?> Now, I was able to fix this by adding: <? for($i = 0; $i < sizeOf($tempType); $i++) if($tempType[$i] == NULL) { array_push($tempType,$i); array_pop($tempType); } ?> which simply takes the new unique array and pushes null values to the top, then pops them out of the array. Configure line: './configure' '--disable-debug' '--with-config-file-path=/usr/local/apache/conf' '--with-mysql=/usr/local/mysql' '--prefix=/usr/local/php4' '--with-apxs=/usr/local/apache/bin/apxs' '--enable-track-vars' '--with-xml' '--enable-track-errors' '--enable-force-cgi-redirect' '--enable-discard-path' '--enable-safe-mode' '--enable-calendar' '--with-jpeg-dir=/usr/local' '--with-png-dir=/usr/local' '--with-gd=/usr' '--enable-gd-native-tt' '--with-zlib-dir=/usr/local' '--with-zlib' '--enable-trans-sid' '--enable-ftp' '--with-png-dir=/usr/local' '--with-gettext' '--enable-memory-limit' '--with-mcrypt' '--with-mcrypt-dir=/usr' '--with-pspell-dir=/usr/local/pspell' If any other information is required, just write an e-mail back.