by zackattack · 17y ago · 0 comments
function getSnsWithoutIds($customerid) {
$query = sprintf("SELECT aim_sn FROM add_queue WHERE aim_id=0 AND cid=%d", $customerid);
$result = mysql_query($query);
$sns = array();
while($row = mysql_fetch_assoc($result)) {
array_push($sns, $row['aim_sn']);
}
return $sns;
}
And then I simply iterate on the array back in the code. $dbh = new DBHandler();
$arr = $dbh->getSnsWithoutIds();
foreach($arr as $ele) { doSomething(); }
What is the advantage to doing things your way?Then, you loop through it again with the foreach. What if you wanted to paginate those results quickly? What if you only wanted a subset of the whole pie?
This class, as I'll show in a future article, can easily be extended to allow for easy pagination and filtering of your data.
BTW I did a test, and it seems that $array[] is a faster way to append.
Classic PHP-style micro-optimization. If you can't use the right algorithm, you can at least make the wrong one run 0.34% faster.