multidimensional array

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

    multidimensional array

    I have a list of nealry 800 products in a database in the following
    format:
    name | price | url
    prod1 | $10 | www.comp1.com
    prod1 | $11 | www.comp1.com
    prod1 | $10.5 | www.comp1.com
    prod1 | $21 | www.comp2.com
    prod1 | $18 | www.comp2.com
    ....
    prod100 | $17 | www.comp3.com
    ....

    There are 8 different companies and 100 different products. I need to
    format the data into the following format:

    name | price (company)
    prod name | comp1 | comp1 | comp3 | ... | comp8
    prod1 | $10 | $11 | $10.5 |...
    prod2 | $21 | null | $18 | ...
    ....
    prod100 | $17 | $13 | $15 | ...

    So my report is 100x8 table filled with the correct data. Because not
    every company manufactures all the products, some cells will be empty
    - prod2[comp2].

    I can't think of any easy way doing it other than creating 100x8 array
    and than filling the cells cell[85][4]='$23', etc..
  • jabarker1@gmail.com

    #2
    Re: multidimensiona l array

    On Jul 6, 3:39 pm, JackpipE <pipe.j...@gmai l.comwrote:
    I have a list of nealry 800 products in a database in the following
    format:
    name | price | url
    prod1 | $10 |www.comp1.com
    prod1 | $11 |www.comp1.com
    prod1 | $10.5 |www.comp1.com
    prod1 | $21 |www.comp2.com
    prod1 | $18 |www.comp2.com
    ...
    prod100 | $17 |www.comp3.com
    ...
    >
    There are 8 different companies and 100 different products. I need to
    format the data into the following format:
    >
    name | price (company)
    prod name | comp1 | comp1 | comp3 | ... | comp8
    prod1 | $10 | $11 | $10.5 |...
    prod2 | $21 | null | $18 | ...
    ...
    prod100 | $17 | $13 | $15 | ...
    >
    So my report is 100x8 table filled with the correct data. Because not
    every company manufactures all the products, some cells will be empty
    - prod2[comp2].
    >
    I can't think of any easy way doing it other than creating 100x8 array
    and than filling the cells cell[85][4]='$23', etc..
    I think this may be the direction you need to take (SQL Distinct):


    You seem to be a fairly smart individual, so you should be able to
    figure out the approach from here, if not then just come back. :)

    Comment

    • Jerry Stuckle

      #3
      Re: multidimensiona l array

      JackpipE wrote:
      I have a list of nealry 800 products in a database in the following
      format:
      name | price | url
      prod1 | $10 | www.comp1.com
      prod1 | $11 | www.comp1.com
      prod1 | $10.5 | www.comp1.com
      prod1 | $21 | www.comp2.com
      prod1 | $18 | www.comp2.com
      ...
      prod100 | $17 | www.comp3.com
      ...
      >
      There are 8 different companies and 100 different products. I need to
      format the data into the following format:
      >
      name | price (company)
      prod name | comp1 | comp1 | comp3 | ... | comp8
      prod1 | $10 | $11 | $10.5 |...
      prod2 | $21 | null | $18 | ...
      ...
      prod100 | $17 | $13 | $15 | ...
      >
      So my report is 100x8 table filled with the correct data. Because not
      every company manufactures all the products, some cells will be empty
      - prod2[comp2].
      >
      I can't think of any easy way doing it other than creating 100x8 array
      and than filling the cells cell[85][4]='$23', etc..
      >
      That's probably the easiest, and if you use integers (rather than
      strings), it won't take that much memory (just add the dollar sign
      later). (if it's in the database that way, you should fix the database).

      Also, your database should be better normalized. Doing so would make it
      much easier. For instance, you could fetch your data and sort by
      product then company, the build on the fly.


      --
      =============== ===
      Remove the "x" from my email address
      Jerry Stuckle
      JDS Computer Training Corp.
      jstucklex@attgl obal.net
      =============== ===

      Comment

      Working...