How to get a row count from a PHP/MYQSL db search

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • leegold2

    How to get a row count from a PHP/MYQSL db search

    Below is some code from a FULLTEXT search. My question is how do I get a
    count of the number of rows found by the search?


    $query="SELECT * FROM balloon_txt WHERE MATCH(access_no , recs_txt)
    AGAINST ('meteorology') ";

    $result = MySQL_query($qu ery);


    Thanks,
    Lee G.
  • Gary L. Burnore

    #2
    Re: How to get a row count from a PHP/MYQSL db search

    On Fri, 16 Jul 2004 02:31:50 GMT, leegold2 <leegold@nospam .net> wrote:
    [color=blue]
    >Below is some code from a FULLTEXT search. My question is how do I get a
    >count of the number of rows found by the search?
    >
    >
    >$query="SELE CT * FROM balloon_txt WHERE MATCH(access_no , recs_txt)
    >AGAINST ('meteorology') ";
    >
    >$result = MySQL_query($qu ery);[/color]

    select count(*) from ball.....


    --
    gburnore@databa six dot com
    ---------------------------------------------------------------------------
    How you look depends on where you go.
    ---------------------------------------------------------------------------
    Gary L. Burnore | ÝÛ³ºÝ³Þ³ºÝ³³ÝÛº ݳ޳ºÝ³Ý³Þ³ºÝ³Ý ÝÛ³
    | ÝÛ³ºÝ³Þ³ºÝ³³ÝÛº ݳ޳ºÝ³Ý³Þ³ºÝ³Ý ÝÛ³
    DataBasix | ÝÛ³ºÝ³Þ³ºÝ³³ÝÛº ݳ޳ºÝ³Ý³Þ³ºÝ³Ý ÝÛ³
    | ÝÛ³ 3 4 1 4 2 ݳ޳ 6 9 0 6 9 ÝÛ³
    Black Helicopter Repair Svcs Division | Official Proof of Purchase
    =============== =============== =============== =============== ===============
    Want one? GET one! http://signup.databasix.com
    =============== =============== =============== =============== ===============

    Comment

    • Michael Austin

      #3
      Re: How to get a row count from a PHP/MYQSL db search

      Gary L. Burnore wrote:
      [color=blue]
      > On Fri, 16 Jul 2004 02:31:50 GMT, leegold2 <leegold@nospam .net> wrote:
      >
      >[color=green]
      >>Below is some code from a FULLTEXT search. My question is how do I get a
      >>count of the number of rows found by the search?
      >>
      >>
      >>$query="SELEC T * FROM balloon_txt WHERE MATCH(access_no , recs_txt)
      >>AGAINST ('meteorology') ";
      >>
      >>$result = MySQL_query($qu ery);[/color]
      >
      >
      > select count(*) from ball.....
      >
      >[/color]

      a search of the PHP docs is a good place to start:

      $numrows = count(mysql_fet ch_array($resul t))
      or
      $numrows = mysql_num_rows( $result)

      --
      Michael Austin.
      Consultant - Available.
      Donations welcomed. Http://www.firstdbasource.com/donations.html
      :)

      Comment

      • dan

        #4
        Re: How to get a row count from a PHP/MYQSL db search

        leegold2 <leegold@nospam .net> wrote in message news:<q6HJc.821 03$qw1.43993@nw rddc01.gnilink. net>...[color=blue]
        > Below is some code from a FULLTEXT search. My question is how do I get a
        > count of the number of rows found by the search?
        >
        >
        > $query="SELECT * FROM balloon_txt WHERE MATCH(access_no , recs_txt)
        > AGAINST ('meteorology') ";
        >
        > $result = MySQL_query($qu ery);
        >
        >
        > Thanks,
        > Lee G.[/color]


        You could use SQL_CALC_FOUND_ ROWS to get a count of returned rows
        regardless of limit.




        example:

        select SQL_CALC_FOUND_ ROWS a,b,c from table limit 10; -- this returns
        10 rows

        select FOUND_ROWS(); -- this returns total count (i.e.: 1,587)



        hth

        Comment

        • /..

          #5
          Re: How to get a row count from a PHP/MYQSL db search

          By 16 Jul 2004 14:59:24 -0700, basement_addict @yahoo.com (dan)
          decided to post "Re: How to get a row count from a PHP/MYQSL db search"
          to comp.lang.php:
          [color=blue]
          >leegold2 <leegold@nospam .net> wrote in message news:<q6HJc.821 03$qw1.43993@nw rddc01.gnilink. net>...[color=green]
          >> Below is some code from a FULLTEXT search. My question is how do I get a
          >> count of the number of rows found by the search?
          >>
          >>
          >> $query="SELECT * FROM balloon_txt WHERE MATCH(access_no , recs_txt)
          >> AGAINST ('meteorology') ";
          >>
          >> $result = MySQL_query($qu ery);
          >>
          >>
          >> Thanks,
          >> Lee G.[/color]
          >
          >
          >You could use SQL_CALC_FOUND_ ROWS to get a count of returned rows
          >regardless of limit.
          >
          >http://dev.mysql.com/doc/mysql/en/SELECT.html
          >
          >
          >example:
          >
          >select SQL_CALC_FOUND_ ROWS a,b,c from table limit 10; -- this returns
          >10 rows
          >
          >select FOUND_ROWS(); -- this returns total count (i.e.: 1,587)
          >
          >
          >
          >hth[/color]

          I think that after your query (above) with SQL_CALC_FOUND_ ROWS, you have to
          run another query to get the count of results:

          $countresult = mysql_query( "SELECT found_rows()" );

          Also, this seems to return the proper full count of records produced by the
          query, regardless of any query-limit set, but only_if_it_is_r un_immediately
          _after_the_firs t_query. The result of the first query is apparently stored
          by php on the server, so it is not lost, and can be read and parsed
          further. If another query is run first, if it includes the
          SQL_CALC_FOUND_ ROWS option, its count is returned; if it doesn't include
          that option, I don't know how the result of a subsequent --
          mysql_query( "SELECT found_rows()" );
          -- would be defined....

          Anther way I've used is:

          $resultCount = mysql_num_rows( $result);

          but this shows how many rows are in the result, which would be equal to any
          limit statement or be fewer than spec'd if fewer records are found than the
          limit.

          Both are useful in their own ways.

          /ts



          --

          find / -iname "*gw*" -exec rm -rf {} \;

          In heaven, there is no beer,
          That's why we drink it here,
          And when we're all gone from here,
          Our friends will be drinking all the beer!
          -- Famous old Czech song about beer --

          Comment

          Working...