Pull Down Menu Query

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

    Pull Down Menu Query

    I'm trying to populate the pulldown menus of a single input form
    through queries from a single table. The three columns are 'name',
    'type', and 'status'. The name table runs to approx row 23, the type,
    to row 8, and status, row 9. . I'm using the following code to
    populate the form pulldown menus::

    <?php
    $query = "SELECT DISTINCT status
    FROM $table";
    $result = mysql_query($qu ery);
    $number = mysql_numrows($ result);

    for ($i=0; $i<$number; $i++) {
    $status = mysql_result($r esult,$i,"statu s");
    print "<option value=\"$status \">$status</option>";
    }

    mysql_close();
    ?>


    The interesting portion here is that 'name' only allows a single blank
    space on the pulldown as I had expected and so does 'status'. 'Type'
    on the other hand, shows 2 blank spaces on the pulldown menu so what's
    with that? Is there some sort of 'end of file marker' that I should
    be inserting to the database columns to get this to read correctly?
    TIA
  • gosha bine

    #2
    Re: Pull Down Menu Query

    On 26.07.2007 09:51 Toby A Inkster wrote:
    cover wrote:
    >
    >$query = "SELECT DISTINCT status
    > FROM $table";
    >
    Most databases optimise GROUP BY better than DISTINCT. Generally speaking,
    if you can avoid DISTINCT, you should: it forces the database engine to
    retrieve rows and then discard them, whereas often, especially with
    well-indexed columns, the engine will be able to do smarter things with
    GROUP BY.
    Don't know about "most" ones, mysql docs explicitly says they're equivalent




    --
    gosha bine

    makrell ~ http://www.tagarga.com/blok/makrell
    php done right ;) http://code.google.com/p/pihipi

    Comment

    • Toby A Inkster

      #3
      Re: Pull Down Menu Query

      gosha bine wrote:
      Don't know about "most" ones, mysql docs explicitly says they're equivalent
      http://dev.mysql.com/doc/refman/5.0/...imization.html
      It says that SELECT DISTINCT and GROUP BY *usually* end up generating the
      same execution plan, so there won't be a performance difference.

      --
      Toby A Inkster BSc (Hons) ARCS
      [Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
      [OS: Linux 2.6.12-12mdksmp, up 36 days, 13:07.]

      Cryptography Challenge

      Comment

      • gosha bine

        #4
        Re: Pull Down Menu Query

        On 27.07.2007 11:46 Toby A Inkster wrote:
        gosha bine wrote:
        >
        >Don't know about "most" ones, mysql docs explicitly says they're equivalent
        >http://dev.mysql.com/doc/refman/5.0/...imization.html
        >
        It says that SELECT DISTINCT and GROUP BY *usually* end up generating the
        same execution plan, so there won't be a performance difference.
        >
        Pretending that you cannot read is probably the worst defense you could
        come up with. ;)

        --
        gosha bine

        makrell ~ http://www.tagarga.com/blok/makrell
        php done right ;) http://code.google.com/p/pihipi

        Comment

        • Captain Paralytic

          #5
          Re: Pull Down Menu Query

          On 27 Jul, 11:31, gosha bine <stereof...@gma il.comwrote:
          On 27.07.2007 11:46 Toby A Inkster wrote:
          >
          gosha bine wrote:
          >
          Don't know about "most" ones, mysql docs explicitly says they're equivalent
          >http://dev.mysql.com/doc/refman/5.0/...imization.html
          >
          It says that SELECT DISTINCT and GROUP BY *usually* end up generating the
          same execution plan, so there won't be a performance difference.
          >
          Pretending that you cannot read is probably the worst defense you could
          come up with. ;)
          >
          --
          gosha bine
          >
          makrell ~http://www.tagarga.com/blok/makrell
          php done right ;)http://code.google.com/p/pihipi
          But it is you who cannot read!

          The manual does NOT (neither explicitly not implicitly) say that GROUP
          BY and DISTINCT are equivalent.

          What it does say is:

          "In most cases, a DISTINCT clause can be considered as a special case
          of GROUP BY."

          And it then says:

          "For example, the following two queries are equivalent: ..."

          The phrase "In most cases" implies that they are not equivalent. If
          they were it would say "In all cases".

          Comment

          • cover

            #6
            Re: Pull Down Menu Query

            On Thu, 26 Jul 2007 08:51:22 +0100, Toby A Inkster
            <usenet200707@t obyinkster.co.u kwrote:

            <snip>

            Hey, looks like some great ideas and I'll give them a try. Thank you
            very much. :-)



            Comment

            Working...