count database lisitngs

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

    count database lisitngs

    How would i go about asking the database how many listings there are with
    the same "Town" field?

    I want a page that eventually says:
    "We found XXX listings in ZZZ"
    Where XXX is the number of listings found and ZZZ is the town.

    Thanks,
    --
    ¿ Trigger ?




  • roger smith

    #2
    Re: count database lisitngs

    try this:

    -------------------------------------------------------------------
    $sql = "SELECT * FROM mytable WHERE town = \"$mytown\" ";
    $query = mysql_query($sq l);
    $num_rows = mysql_num_rows( $query);
    echo "We found " .$num_rows ." listings of " .$mytown;
    -------------------------------------------------------------------

    look here for more ::


    is that what you want ?

    Neil Trigger wrote:[color=blue]
    > How would i go about asking the database how many listings there are with
    > the same "Town" field?
    >
    > I want a page that eventually says:
    > "We found XXX listings in ZZZ"
    > Where XXX is the number of listings found and ZZZ is the town.
    >
    > Thanks,
    > --
    > ¿ Trigger ?
    > http://www.magic2k.com/
    > http://www.oddmap.co.uk
    >
    >[/color]

    Comment

    • Gerard

      #3
      Re: count database lisitngs

      mysql_num_rows( ) was not always so efective.

      If it fails try this:

      $count = mysql_fetch_arr ay(mysql_query( "select count(*) from table where
      town=example")) ;
      echo "$count";

      It has been always useful for me.

      Regards

      Domin


      Comment

      • Tim Van Wassenhove

        #4
        Re: count database lisitngs

        On 2003-12-18, Gerard <garganel@WYTNI Jwp.pl> wrote:[color=blue]
        > mysql_num_rows( ) was not always so efective.
        >
        > If it fails try this:
        >
        > $count = mysql_fetch_arr ay(mysql_query( "select count(*) from table where
        > town=example")) ;
        > echo "$count";[/color]

        I think you are doing "weird stuff" to get the count(*) ...

        $result = mysql_query("SE LECT COUNT(*) as count FROM TABLE WHERE Town='example'" );
        $row = mysql_fetch_ass oc($result);
        Now it is in $row['count'] ;)

        --
        verum ipsum factum

        Comment

        • lazo

          #5
          Re: count database lisitngs

          I think it's better to use ...

          $sql = "SELECT count(*) as numRows FROM mytable WHERE town = \"$mytown\" ";
          $query = mysql_query($sq l);
          $aRow = mysql_fetch_arr ay($query);
          echo "We found " .$aRow[numRows] ." listings of " .$mytown;

          .... because in this case MySql don't return useless data.

          Comment

          Working...