listing alphabetically in trwo columns

listing alphabetically in trwo columns

am 31.03.2007 09:14:13 von leader

I'm trying to list meteorological data reports, from an ever-varying
number of locations, in two columns, side-by-side - the first half of
the list alphabetically in the left column and then the second half in
the right column. In the example below, numbering the locations for
the purpose of the example, it has to be something like this, using,
say, 60 locations -

$Query="SELECT * FROM obervations order by location";
$Result=mysql_db_query ($DBName, $Query, $Link);
while ($Row=mysql_fetch_array ($Result))
(










$Row[location1] $Row[humidity1] $Row[oktas1] $Row[location31] $Row[humidity31] $Row[oktas31]
$Row[location2] $Row[humidity2] $Row[oktas2] $Row[location32] $Row[humidity32] $Row[oktas32]



and so on until the database is exhausted.
I've tried using arrays to store each data item but I think it's
clumsy. Is there a more elegant way to do it?
TIA.

Re: listing alphabetically in trwo columns

am 06.04.2007 17:33:24 von Erwin Moller

leader@congress.hotmail.com wrote:

> I'm trying to list meteorological data reports, from an ever-varying
> number of locations, in two columns, side-by-side - the first half of
> the list alphabetically in the left column and then the second half in
> the right column. In the example below, numbering the locations for
> the purpose of the example, it has to be something like this, using,
> say, 60 locations -
>
> $Query="SELECT * FROM obervations order by location";
> $Result=mysql_db_query ($DBName, $Query, $Link);
> while ($Row=mysql_fetch_array ($Result))
> (
>
>


>
>
>
>
>
>
>
>
>
$Row[location1] $Row[humidity1] $Row[oktas1]$Row[location31] $Row[humidity31] $Row[oktas31]
$Row[location2] $Row[humidity2] $Row[oktas2]$Row[location32] $Row[humidity32] $Row[oktas32]

>
>
> and so on until the database is exhausted.
> I've tried using arrays to store each data item but I think it's
> clumsy. Is there a more elegant way to do it?
> TIA.

Why is that clumsy?

But another thought could be:
Rebuild your html so it contains a outer table.







.. first 30 results go here



.. next 30 results go here




That way you only have to find the middle one and let php spit out the




part, and you can 'normally' traverse through your results from the
database.

But putting things in an array first is not clumsy, unless you have such a
huge amount of data you get into resourcestrouble (eg the 8MB default PHP
memory allocation)

Regards,
Erwin Moller

Re: listing alphabetically in trwo columns

am 07.04.2007 11:15:06 von leader

On Fri, 06 Apr 2007 17:33:24 +0200, Erwin Moller
wrote:

>leader@congress.hotmail.com wrote:
>
>> I'm trying to list meteorological data reports, from an ever-varying
>> number of locations, in two columns, side-by-side - the first half of
>> the list alphabetically in the left column and then the second half in
>> the right column. In the example below, numbering the locations for
>> the purpose of the example, it has to be something like this, using,
>> say, 60 locations -
>>
>> $Query="SELECT * FROM obervations order by location";
>> $Result=mysql_db_query ($DBName, $Query, $Link);
>> while ($Row=mysql_fetch_array ($Result))
>> (
>>
>>


>>
>>
>>
>>
>>
>>
>>
>>
>>
$Row[location1] $Row[humidity1] $Row[oktas1]$Row[location31] $Row[humidity31] $Row[oktas31]
$Row[location2] $Row[humidity2] $Row[oktas2]$Row[location32] $Row[humidity32] $Row[oktas32]

>>
>>
>> and so on until the database is exhausted.
>> I've tried using arrays to store each data item but I think it's
>> clumsy. Is there a more elegant way to do it?
>> TIA.
>
>Why is that clumsy?
>
>But another thought could be:
>Rebuild your html so it contains a outer table.
>
>
>
>
>
>

>
> .. first 30 results go here
>

>

>
> .. next 30 results go here
>

>

>
>
>That way you only have to find the middle one and let php spit out the
>
>
>
>
>part, and you can 'normally' traverse through your results from the
>database.
>
>But putting things in an array first is not clumsy, unless you have such a
>huge amount of data you get into resourcestrouble (eg the 8MB default PHP
>memory allocation)
>
>Regards,
>Erwin Moller
>

I just "felt" it was clumsy and thought that it might be an
often-enough required ability that there might be an established piece
of code.
Anyway, thank you for your response.

Re: listing alphabetically in trwo columns

am 07.04.2007 11:46:37 von Shion

leader@congress.hotmail.com wrote:
> I'm trying to list meteorological data reports, from an ever-varying
> number of locations, in two columns, side-by-side - the first half of
> the list alphabetically in the left column and then the second half in
> the right column. In the example below, numbering the locations for
> the purpose of the example, it has to be something like this, using,
> say, 60 locations -
>
> $Query="SELECT * FROM obervations order by location";
> $Result=mysql_db_query ($DBName, $Query, $Link);
> while ($Row=mysql_fetch_array ($Result))
> (
>
>


>
>
>
>
>
>
>
>
>
$Row[location1] $Row[humidity1] $Row[oktas1]$Row[location31] $Row[humidity31] $Row[oktas31]
$Row[location2] $Row[humidity2] $Row[oktas2]$Row[location32] $Row[humidity32] $Row[oktas32]

>
>
> and so on until the database is exhausted.
> I've tried using arrays to store each data item but I think it's
> clumsy. Is there a more elegant way to do it?
> TIA.

There is quite a lot anti-table feelings at the html-newsgroups, so you may
want to avoid as much as possible to use those, you could use Erwins model,
but instead of an outer table you could use div-tags, one for the left table
and another for the right table.

Another method would be to store the data into an array and then split it in
two (array_slice) and loop throe the arrays simultaneous.

I do favor the second option.

--

//Aho

Re: listing alphabetically in trwo columns

am 09.04.2007 13:44:19 von leader

On Sat, 07 Apr 2007 11:46:37 +0200, "J.O. Aho"
wrote:

>leader@congress.hotmail.com wrote:
>> I'm trying to list meteorological data reports, from an ever-varying
>> number of locations, in two columns, side-by-side - the first half of
>> the list alphabetically in the left column and then the second half in
>> the right column. In the example below, numbering the locations for
>> the purpose of the example, it has to be something like this, using,
>> say, 60 locations -
>>
>> $Query="SELECT * FROM obervations order by location";
>> $Result=mysql_db_query ($DBName, $Query, $Link);
>> while ($Row=mysql_fetch_array ($Result))
>> (
>>
>>


>>
>>
>>
>>
>>
>>
>>
>>
>>
$Row[location1] $Row[humidity1] $Row[oktas1]$Row[location31] $Row[humidity31] $Row[oktas31]
$Row[location2] $Row[humidity2] $Row[oktas2]$Row[location32] $Row[humidity32] $Row[oktas32]

>>
>>
>> and so on until the database is exhausted.
>> I've tried using arrays to store each data item but I think it's
>> clumsy. Is there a more elegant way to do it?
>> TIA.
>
>There is quite a lot anti-table feelings at the html-newsgroups,
Yeah, I saw that; some of them get almost hysterical on the subject.
> so you may
>want to avoid as much as possible to use those, you could use Erwins model,
>but instead of an outer table you could use div-tags, one for the left table
>and another for the right table.
>
>Another method would be to store the data into an array and then split it in
>two (array_slice) and loop throe the arrays simultaneous.
>
>I do favor the second option.

I finally went the way of -
select location from table
$count=num_affected_rows
if ($count%2) $count++
$half_count=$count/2
then -
select aplhabetically limit 0, $half_count
and -
select alphabetically limit $half_count, $count
into a left table and a right table.
It all seems to work. Thanks for the suggestions.