arranging data results in multiple tables.
am 07.12.2006 01:38:59 von toodi4
I'm trying to arrange some data output that will go into a series of
identical tables:
The data needs to be arranged as such:
Company 1 item 1 subitem 1
subitem 2
item 2 subitem A
subitem B
all data comes from a single table, and the above all represent
individual rows. So in the db, Company 1 would be in all rows, item 1
would be in the rows of the two subitems, etc. I'm assuming I could
get those fields to not repeat by using 'Distinct.'
What I'm having a problem with is that the above would be within 1
table, with its own set of column labels and bordering. And then
additional identical tables would follow for Company 2, Company 3, etc.
(actually, it is a little more complicated because each Company table
has to be sub-divided with different categories of items. But I
suspect the solution will be within the same concept)
How do I get php to create a separate table for each Company? I am
very used to using 'while' loops to populate tables. But usually when
I do this I just create separate tables for separate queries. I'm not
certain of the way to do the loop so for every Company a separate table
starts.
I don't need the full coding, I just need to be pointed in the right
direction.
Thanks!
Re: arranging data results in multiple tables.
am 07.12.2006 05:24:53 von toodi4
toodi4 wrote:
> I'm trying to arrange some data output that will go into a series of
> identical tables:
>
> The data needs to be arranged as such:
>
> Company 1 item 1 subitem 1
> subitem 2
>
> item 2 subitem A
> subitem B
>
>
> all data comes from a single table, and the above all represent
> individual rows. So in the db, Company 1 would be in all rows, item 1
> would be in the rows of the two subitems, etc. I'm assuming I could
> get those fields to not repeat by using 'Distinct.'
>
> What I'm having a problem with is that the above would be within 1
> table, with its own set of column labels and bordering. And then
> additional identical tables would follow for Company 2, Company 3, etc.
> (actually, it is a little more complicated because each Company table
> has to be sub-divided with different categories of items. But I
> suspect the solution will be within the same concept)
>
> How do I get php to create a separate table for each Company? I am
> very used to using 'while' loops to populate tables. But usually when
> I do this I just create separate tables for separate queries. I'm not
> certain of the way to do the loop so for every Company a separate table
> starts.
>
> I don't need the full coding, I just need to be pointed in the right
> direction.
>
> Thanks!
I think I might have figured this out after posting it. Would the way
to do this be to run queries within the while loop? Something like
this (rough)
query = "select company from table";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result))
{
$company = $row['company'];
$display .= "
company |
";
$get_items_sql = "select item from where company =$company";
$get_itmes_result = mysql_query($query);
while ($row1 = mysql_fetch_array($get_items_result))
{
$item = $row1['item'];
$display .= "item | ";
-------------
and then another while loop for subitems.
I'll test this out. But if anyone has any feedback, that would be
helpful.
Thanks.
Re: arranging data results in multiple tables.
am 07.12.2006 08:27:24 von toodi4
> I think I might have figured this out after posting it. Would the way
> to do this be to run queries within the while loop? Something like
> this (rough)
>
> query = "select company from table";
> $result = mysql_query($query);
> while ($row = mysql_fetch_array($result))
> {
> $company = $row['company'];
>
> $display .= "
company |
";
>
> $get_items_sql = "select item from where company =$company";
> $get_itmes_result = mysql_query($query);
>
> while ($row1 = mysql_fetch_array($get_items_result))
> {
> $item = $row1['item'];
>
> $display .= "item | ";
> -------------
>
> and then another while loop for subitems.
>
>
Well that didn't work as I expected. I probably should have tested it
before posting. The second query doesn't seem to like the row item
$company. Even when I tried hard coding a value just to see what the
output would be, the results I got were weird. The original query rows
each got returned for the number of rows in the original query, 15 x
15.
Anyway, I did base this off of something I had read. But I'm really
stuck now and need help.