help with mySQL and ORDER BY

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

    help with mySQL and ORDER BY

    I have a table in a mySQL database that has 56 fields: 01, 02, 03, 04, etc
    up to 56.
    Each field has only 1 record in it. They get changed, updated, constantly,
    but always remaining one record.

    Is there a way to do a SELECT * on the table, and then order them in ASC or
    DESC by the fields as opposed to the records in a field? (They're all
    numeric fields.)

    Did that make sense?

    Thanks for any help!!
    Liam


  • Jochen Daum

    #2
    Re: help with mySQL and ORDER BY

    Hi !

    On Sun, 22 Feb 2004 21:19:20 GMT, "LRW" <druid@NOSPAHMc elticbear.com>
    wrote:
    [color=blue]
    >I have a table in a mySQL database that has 56 fields: 01, 02, 03, 04, etc
    >up to 56.
    >Each field has only 1 record in it. They get changed, updated, constantly,
    >but always remaining one record.
    >
    >Is there a way to do a SELECT * on the table, and then order them in ASC or
    >DESC by the fields as opposed to the records in a field? (They're all
    >numeric fields.)
    >
    >Did that make sense?
    >[/color]
    I understand what you want, but a database doesn't suppport that. You
    have to use 56 records, which is a better data model anyway.

    Jochen
    --
    Jochen Daum - Cabletalk Group Ltd.
    PHP DB Edit Toolkit -- PHP scripts for building
    database editing interfaces.
    Download PHP DB Edit Toolkit for free. PHP DB Edit Toolkit is a set of PHP classes makes the generation of database edit interfaces easier and faster. The main class builds tabular and form views based on a data dictionary and takes over handling of insert/update/delete and user input.

    Comment

    • LRW

      #3
      Re: help with mySQL and ORDER BY

      "Jochen Daum" <jochen.daum@ca ns.co.nz> wrote in message
      news:k57i301abc 9hs61k5o10fet0i blrnvn0g6@4ax.c om...[color=blue]
      > Hi !
      >
      > On Sun, 22 Feb 2004 21:19:20 GMT, "LRW" <druid@NOSPAHMc elticbear.com>
      > wrote:
      >[color=green]
      > >Is there a way to do a SELECT * on the table, and then order them in ASC[/color][/color]
      or[color=blue][color=green]
      > >DESC by the fields as opposed to the records in a field? (They're all
      > >numeric fields.)
      > >[/color]
      > I understand what you want, but a database doesn't suppport that. You
      > have to use 56 records, which is a better data model anyway.
      >[/color]

      Hrrmm. Is there some way to be able to sort/order the results by numeric
      value? Highest to lowest?
      Something while making the WHILE array perhaps?
      I don't really know how to begin looking to do something like that. If it's
      possible, a simple pointer, the name of the process, is all I need and I'll
      go look into it.
      I just want to be able to dynamically sort the results on a Webpage in
      realtime. =/

      Thanks!
      Liam


      Comment

      • Jochen Daum

        #4
        Re: help with mySQL and ORDER BY

        Hi !

        On Sun, 22 Feb 2004 22:34:54 GMT, "LRW" <druid@NOSPAHMc elticbear.com>
        wrote:
        [color=blue]
        >"Jochen Daum" <jochen.daum@ca ns.co.nz> wrote in message
        >news:k57i301ab c9hs61k5o10fet0 iblrnvn0g6@4ax. com...[color=green]
        >> Hi !
        >>
        >> On Sun, 22 Feb 2004 21:19:20 GMT, "LRW" <druid@NOSPAHMc elticbear.com>
        >> wrote:
        >>[color=darkred]
        >> >Is there a way to do a SELECT * on the table, and then order them in ASC[/color][/color]
        >or[color=green][color=darkred]
        >> >DESC by the fields as opposed to the records in a field? (They're all
        >> >numeric fields.)
        >> >[/color]
        >> I understand what you want, but a database doesn't suppport that. You
        >> have to use 56 records, which is a better data model anyway.
        >>[/color]
        >
        >Hrrmm. Is there some way to be able to sort/order the results by numeric
        >value? Highest to lowest?
        >Something while making the WHILE array perhaps?
        >I don't really know how to begin looking to do something like that. If it's
        >possible, a simple pointer, the name of the process, is all I need and I'll
        >go look into it.[/color]

        www.php.net, search for array_sort or array_ksort or array_usort


        [color=blue]
        >I just want to be able to dynamically sort the results on a Webpage in
        >realtime. =/[/color]

        realtime means with or without reload.

        Jochen
        --
        Jochen Daum - Cabletalk Group Ltd.
        PHP DB Edit Toolkit -- PHP scripts for building
        database editing interfaces.
        Download PHP DB Edit Toolkit for free. PHP DB Edit Toolkit is a set of PHP classes makes the generation of database edit interfaces easier and faster. The main class builds tabular and form views based on a data dictionary and takes over handling of insert/update/delete and user input.

        Comment

        • Pedro Graca

          #5
          Re: help with mySQL and ORDER BY

          LRW wrote:[color=blue]
          > I have a table in a mySQL database that has 56 fields: 01, 02, 03, 04, etc
          > up to 56.[/color]
          [color=blue]
          > Is there a way to do a SELECT * on the table, and then order them in ASC or
          > DESC by the fields as opposed to the records in a field? (They're all
          > numeric fields.)
          >
          > Did that make sense?[/color]

          Something like this?
          using MySQL v 4.0.17

          : mysql> create table t (`01` int, `02` int, `03` int, `04` int);
          : mysql> insert into t values(8, 5, 3, 7);
          : mysql> select '01' as id, `01` as value from t
          : -> union
          : -> select '02' as id, `02` as value from t
          : -> union
          : -> select '03' as id, `03` as value from t
          : -> union
          : -> select '04' as id, `04` as value from t
          : -> order by value;
          : +----+-------+
          : | id | value |
          : +----+-------+
          : | 03 | 3 |
          : | 02 | 5 |
          : | 04 | 7 |
          : | 01 | 8 |
          : +----+-------+
          : 4 rows in set (0.00 sec)

          HTH
          --
          --= my mail box only accepts =--
          --= Content-Type: text/plain =--
          --= Size below 10001 bytes =--

          Comment

          Working...