php - SQL LIMIT VS Loop Limit -
php - SQL LIMIT VS Loop Limit -
i browsing around stack overflow attempting find how limit sql query while loop , came across code.
$count = 0; while ($count < 4 && $info = mysql_fetch_assoc($result)) { //stuff $count++; } q 1: difference between code , using sql limit clause?
q 2: reason want utilize code, rather using limit?
with code, mysql server send results client, client ignores after 4th row. server has more work, , more bandwidth used between client , server.
they might want utilize mysql_num_rows() find out how many total rows selected, though want display first 4. however, mysql provides way limit -- can set sql_calc_found_rows alternative in select clause, , utilize select found_rows() total number of rows. there's no reason, except don't know feature.
php sql count while-loop limit
Comments
Post a Comment