php - Notice: Unknown: Skipping numeric key 1 in Unknown on line 0 -
i have following code:
include 'includes/connect.php'; $sp= "clot"; $selectall = mysqli_prepare($connection, "select count prices category = ? order ppu limit 11"); mysqli_stmt_bind_param($selectall, 's', $sp); mysqli_stmt_execute($selectall); $resulttotal = mysqli_stmt_get_result($selectall); $x=1; while($row = mysqli_fetch_array($resulttotal, mysqli_assoc)){ $_session[$x] = $row['count']; $x++; } $y=1; while(isset($_session[$y])){ if($y==11){ $_session['nextstart'] = $_session[$y]; unset($_session[11]); } else{ echo($y); echo("<br>"); echo($_session[$y]); echo("<br>"); $y++; } }
which outputs expected string of numbers (1, 17, 2, 18...) error message(ten times, key 1, key 2, key 3, , on):
notice: unknown: skipping numeric key 1 in unknown on line 0
looking error up, answer find putting array superglobal cause this. don't believe i've put array in, $row['count']
string, isn't it? couldn't find entries on stackoverflow error.
what causes error, , should fix it? (the shown code me experimenting , planning design endless pagination using database.)
the php session storage mechanism built around "registering" variables, keys in $_session
must names treated variables in own right.
this means $_session[42]
invalid, because $42
wouldn't valid variable name, , since $foo[42]
, $foo['42']
refer same thing, $_session['42']
invalid well.
the solution either use prefix on session variables (e.g. $_session['row_count_' . $x] = $row['count'];
) or make them array, can loop on etc later (e.g. $_session['row_counts'] = array(); ... $_session['row_counts'][$x] = $row['count'];
)
note: limitation part of "serialization handler" used when writing session disk, why errors have no context (they're fired while php shutting down). in recent versions of php there setting of session.serialize_handler doesn't have limitation:
php_serialize available php 5.5.4. php_serialize uses plain serialize/unserialize function internally , not have limitations php , php_binary have. older serialize handlers cannot store numeric index nor string index contains special characters (| , !) in $_session. use php_serialize avoid numeric index or special character errors @ script shutdown.
Comments
Post a Comment