Changeset 80
- Timestamp:
- 05/26/2007 02:52:47 AM (19 months ago)
- Files:
-
- 1 modified
-
trunk/system/database/DB_active_rec.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/system/database/DB_active_rec.php
r24 r80 696 696 697 697 /** 698 * Count Records 699 * 700 * Count table records by using active record conditions 701 * please use count_all() if you don't need active record conditions 702 * performance of count_records() is 25% slower than count_all() 703 * 704 * @access public 705 * @param string 706 * @return string 707 */ 708 function count_records($table = '') 709 { 710 if ($table == '') 711 { 712 return '0'; 713 } 714 else 715 { 716 $this->from($table); 717 } 718 719 $sql = $this->_compile_select(TRUE); 720 721 $query = $this->query($sql); 722 $result = $query->result(); 723 $this->_reset_select(); 724 return $result[0]->numrows; 725 } 726 727 // -------------------------------------------------------------------- 728 729 /** 698 730 * Use Table - DEPRECATED 699 731 * … … 747 779 * 748 780 * @access private 781 * @param boolean $count TRUE for counting records (to be used by count_records()) 749 782 * @return string 750 783 */ 751 function _compile_select( )784 function _compile_select($count = FALSE) 752 785 { 753 786 $sql = ( ! $this->ar_distinct) ? 'SELECT ' : 'SELECT DISTINCT '; 754 755 $sql .= (count($this->ar_select) == 0) ? '*' : implode(', ', $this->ar_select); 787 788 if ($count == FALSE) 789 { 790 $select = '*'; 791 } 792 else 793 { 794 $select = 'COUNT(*) AS numrows'; 795 } 796 797 $sql .= (count($this->ar_select) == 0) ? $select : implode(', ', $this->ar_select); 756 798 757 799 if (count($this->ar_from) > 0)
