Connecting Tech Pros Worldwide Help | Site Map

multidimensional array

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 6th, 2008, 10:45 PM
JackpipE
Guest
 
Posts: n/a
Default 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..

  #2  
Old July 7th, 2008, 12:25 AM
jabarker1@gmail.com
Guest
 
Posts: n/a
Default 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, 12:55 AM
Jerry Stuckle
Guest
 
Posts: n/a
Default 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
==================

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.