function get_arr($sql){
$i = 0;
$result = mysql_query($sql);
while ($arr[$i] = mysql_fetch_array($result)){ $i++; };
array_slice ($arr, 0, -1);
mysql_free_result($result);
return $arr;
}
If I ran that without the array_slice I get a blank entry into the array as it executes the mysql_fetch before kicking out of the while loop. As yet I haven't run into any problems with losing the last entry from a query, but I could see it might be a problem. Are there any situations where I could lose a valid entry from my query?
If so should I be putting the result of the query into a variable, checking its not empty, then putting it into my array something like:
function get_arr($sql){
$i = 0;
$result = mysql_query($sql);
while ($val = mysql_fetch_array($result)){
if ($val != ""){
arr[$i] = $val;
};
$i++;
};
mysql_free_result($result);
return $arr;
}
Just checking as the first is shorter and quicker and I'll probably reuse the function in other projects and wanted to have it perfect.