Re: Paging Help
| From: | Adam Zey | Date: | Tue, 20 Jun 2006 17:51:57 +0000 |
| Subject: | Re: Paging Help | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-238419@lists.php.net to get a copy of this message | ||
Andrei wrote:
Querying all data in the first place is a waste, and the practice of seeking through a dataset seems silly when MySQL has the "LIMIT" feature to specify which data you want to return. I believe the proper way to do this would be something like this (Simplified example, of course): $query = "SELECT SQL_CALC_FOUND_FOWS * FROM foo LIMIT 30, 10"; $result = mysql_query($query); $query = "SELECT found_rows()"; $num_rows = mysql_result(mysql_query($query), 0); That should be much faster than the methods used by either of you guys. As a comment, it would have been better to do "SELECT COUNT(*) FROM foo" and reading the result rather than doing "SELECT * FROM foo" and then mysql_num_rows(). Don't ask MySQL to collect data if you're not going to use it! That actually applies to why you shouldn't use mysql_data_seek either. Regards, Adam.Since you query all enregs from table why not query all first andthe do mysql_data_seek on result? // Query to show $query_rsData = "SELECT * FROM {table} ORDER BY {Whatever field}"; $rsData = mysql_query($query_rsData, $DB_CONECTION); $num_total_records = mysql_num_rows( $rsData ); $total_pag = ceil($num_total_records / $NUM_RECORDS); if( $pag < 1 )$pag = 1;elseif( $pag > $total_pag )$pag = $total_pag;$start_enreg = ($pag-1) * $NUM_RECORDS; @mysql_data_seek( $rsData, $start_enreg ); while( ($result = mysql_fetch_object( $rsData )) ) {// display data...}