Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    Senior Coder
    Join Date
    Dec 2005
    Location
    Slovenia
    Posts
    1,960
    Thanks
    120
    Thanked 76 Times in 76 Posts

    Sql_calc_found_rows

    Anyone using that ?
    I mean,SELECT FOUND_ROWS() always returns 1.
    Was playing with that in mysql query browser, 1 tab select SQL_CALC_FOUND_ROWS .. limit ..., the other SELECT FOUND_ROWS()
    result of second allways 1.
    So I pushed thing in stored proc, c_sql of course containing SQL_CALC_FOUND_ROWS,same thing.


    in stored proc:
    Code:
    DELIMITER $$
     
    DROP PROCEDURE IF EXISTS `getOnePageOfDataNew` $$
    CREATE DEFINER=`root`@`localhost` PROCEDURE `getOnePageOfDataNew`(OUT i_result INT,
                                                                     IN  c_sql text,
                                                                     IN  c_limit VARCHAR(60)
                                                                     )
    BEGIN
     
    DECLARE tmpInt INT;
     
    DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
    BEGIN
      set i_result = -1;
    END;
     
    Set @i_count = 0;
     
    SET @s = CONCAT(c_sql," ",c_limit);
    prepare stmt from @s;
    execute stmt;
    DEALLOCATE PREPARE stmt;
     
    SELECT FOUND_ROWS() into @i_count;
    set i_result = @i_count;
     
    END $$
     
    DELIMITER ;
    by some miracle, this works correct:

    Code:
    Select SQL_CALC_FOUND_ROWS some_field
    FROM  table
    LIMIT 0,18
    
    union
    
    SELECT FOUND_ROWS()

    Any explanation, how is this ment to work ?
    Last edited by BubikolRamios; 06-14-2011 at 01:05 AM.
    Found a flower or bug and don't know what it is ?
    agrozoo.net galery
    if you don't spot search button at once, there is search form:
    agrozoo.net galery search


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •