I'm not sure I did the FOUND_ROWS correctly see $noRecs? I enclose my sql statement with the filters and limit. I need the total $noRecs for paging without the limit but when I echo the $noRecs I get the number 1 which might be the page instead.? And the $noPages is 0.01 which is right. The number of records on this query is 21 .


$sql="SELECT SQL_CALC_FOUND_ROWS bu, cart_id, ndc, error_flag, item_id, description, upc, ndc_uom, std_uom ";
$sql.="FROM inventory, link ";
$sqlWhere="WHERE ndc=ndc ";

    if ($bu!=''){ $sqlWhere.="AND bu ='$bu' ";}
    if ($cart_id !='') { $sqlWhere.="AND cart_id='$cart_id' ";}
    if (($zoneid !='') && ($zonenm!='')) { $sqlWhere.="AND zoneid ='$zoneid'AND  zonenm='$zonenm' ";}
    if ( $error_flag !=''){$sqlWhere.="AND error_flag='$error_flag' ";}
    $sqlOrder="ORDER BY $order ";
    $sql.=$sqlWhere;
    $limit_start= ($page * PAGE_LIMIT) - 100;
    $sqlLimit= "LIMIT $limit_start,100 ";
    $noPages=$noRecs/1
    $sql.=  $sqlOrder ." " .$sqlLimit ;

 $result= mysql_query($sql);
if ( !$result ) {die("<font color='red'>Invalid query:</font>" . mysql_error() . "<br />$sql");}

$noRecs= mysql_num_rows(mysql_query('SELECT FOUND_ROWS()'));
echo "Number of Recs  :$noRecs";

    you will always get "1" as your counting the number of rows returned, not checking the value returned.

      Okay, I got it. The num_of_rows($result) gets only the first row of the query.
      In the do/while loop all of the rows get displayed. So I think I'm tracking.
      The SeLECT SQL_CALC_FOUND_ROWS xxxxx
      queries the records with the limit
      The $result =mysql_query((FOUND_ROWS()) does the query without the limit
      Then somehow magically in the do/while
      mysql_fetch_array() goes back to querying the records with the limit?
      Is this all right?

      If so I still don't know how to get the total number records without the limit.
      Do I do a for each to get the count right after the SELECT FOUND_ROWS??

      thanks,

      if ($bu!=''){ $sqlWhere.="AND bu ='$bu' ";}
          if ($cart_id !='') { $sqlWhere.="AND cart_id='$cart_id' ";}
          if (($zoneid !='') && ($zonenm!='')) { $sqlWhere.="AND zoneid ='$zoneid'AND  zonenm='$zonenm' ";}
          if ( $error_flag !=''){$sqlWhere.="AND error_flag='$error_flag' ";}
          $sqlOrder="ORDER BY $order ";
          $sql.=$sqlWhere;
          $limit_start= ($page * 100) - 100;
          $sqlLimit= "LIMIT $limit_start,100 ";
          $sql.=  $sqlOrder ." " .$sqlLimit ;
      
      $result= mysql_query('SELECT FOUND_ROWS()');
      $noRecs=  ?????
      
      if ( !$result ) {die("<font color='red'>Invalid query:</font>" . mysql_error() . "<br />$sql");}
      
      
        jrough;10957126 wrote:

        Okay, I got it. The num_of_rows($result) gets only the first row of the query.

        no, it gets a count of the rows returned

        jrough;10957126 wrote:

        If so I still don't know how to get the total number records without the limit.
        Do I do a for each to get the count right after the SELECT FOUND_ROWS??

          $Result = mysql_query( "SELECT FOUND_ROWS( )" );
            print_r( mysql_fetch_array( $Result ) );
          Write a Reply...