Connecting Tech Pros Worldwide Help | Site Map

multidimensional array

JackpipE
Guest
 
Posts: n/a
#1: Jul 6 '08
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
Guest
 
Posts: n/a
#2: Jul 7 '08

re: multidimensional array


On Jul 6, 3:39*pm, JackpipE <pipe.j...@gmail.comwrote:
Quote:
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):
http://www.sql-tutorial.com/sql-distinct-sql-tutorial/

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. :)
Jerry Stuckle
Guest
 
Posts: n/a
#3: Jul 7 '08

re: multidimensional array


JackpipE wrote:
Quote:
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@attglobal.net
==================

Closed Thread