force order

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

    #1

    force order

    I'm working on a web page in php with a mysql DB. I'm trying to list
    some products with some other information but I'm having trouble tying
    them together. Is there a way to force a very specific order to be
    returned? What I need to be able to do is have a query like

    "select * from products where prodID = 'thing1' or prodID = 'thing2'
    or prodID = 'thing3'...

    but I need it to come back in that EXACT order, product matching
    thing1 first thing2 second and so on.

    Any ideas?

    Thanks,
    Tim
  • Aggro

    #2
    Re: force order

    Odarr wrote:
    [color=blue]
    > I'm working on a web page in php with a mysql DB. I'm trying to list
    > some products with some other information but I'm having trouble tying
    > them together. Is there a way to force a very specific order to be
    > returned? What I need to be able to do is have a query like
    >
    > "select * from products where prodID = 'thing1' or prodID = 'thing2'
    > or prodID = 'thing3'...
    >
    > but I need it to come back in that EXACT order, product matching
    > thing1 first thing2 second and so on.[/color]

    use:
    order by fieldname
    at the end of your query.

    Instead of names, use integer id values in the field which you want to
    use for ordering, that way you can easily deside that 'thing1' = 1,
    'thing2' = 2, etc, and ordering them is simple and fast.

    Comment

    • Aggro

      #3
      Re: force order

      Odarr wrote:
      [color=blue]
      > I'm working on a web page in php with a mysql DB. I'm trying to list
      > some products with some other information but I'm having trouble tying
      > them together. Is there a way to force a very specific order to be
      > returned? What I need to be able to do is have a query like
      >
      > "select * from products where prodID = 'thing1' or prodID = 'thing2'
      > or prodID = 'thing3'...
      >
      > but I need it to come back in that EXACT order, product matching
      > thing1 first thing2 second and so on.[/color]

      use:
      order by fieldname
      at the end of your query.

      Instead of names, use integer id values in the field which you want to
      use for ordering, that way you can easily deside that 'thing1' = 1,
      'thing2' = 2, etc, and ordering them is simple and fast.

      Comment

      • Aggro

        #4
        Re: force order

        Odarr wrote:
        [color=blue]
        > I'm working on a web page in php with a mysql DB. I'm trying to list
        > some products with some other information but I'm having trouble tying
        > them together. Is there a way to force a very specific order to be
        > returned? What I need to be able to do is have a query like
        >
        > "select * from products where prodID = 'thing1' or prodID = 'thing2'
        > or prodID = 'thing3'...
        >
        > but I need it to come back in that EXACT order, product matching
        > thing1 first thing2 second and so on.[/color]

        use:
        order by fieldname
        at the end of your query.

        Instead of names, use integer id values in the field which you want to
        use for ordering, that way you can easily deside that 'thing1' = 1,
        'thing2' = 2, etc, and ordering them is simple and fast.

        Comment

        Working...