Connecting Tech Pros Worldwide Help | Site Map

multidimensional array

  #1  
Old July 6th, 2008, 11:45 PM
JackpipE
Guest
 
Posts: n/a
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..
  #2  
Old July 7th, 2008, 01:25 AM
jabarker1@gmail.com
Guest
 
Posts: n/a

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. :)
  #3  
Old July 7th, 2008, 01:55 AM
Jerry Stuckle
Guest
 
Posts: n/a

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Multidimensional array - search for relationships LittleCake answers 5 December 3rd, 2007 11:25 PM
Flattening Multidimensional array to unique values Chuy08 answers 1 February 12th, 2007 06:25 PM
Delete ASP Multidimensional Array answers 10 March 23rd, 2006 02:15 PM
foreach loop in Multidimensional Array chris answers 2 November 17th, 2005 08:56 AM
copying to a multidimensional array? Mark Smith answers 1 November 16th, 2005 03:27 AM