one long list

one long list

am 23.01.2006 22:30:20 von Chris

can anyone help?
I am displaying a list the results are about 60 retailers this will display
the result in one long list is there a way I can split the results into say
3 or 4 columns instead of one long list?
thanks

function show_brand() {
global $id_link;
$sql_brand="select * from brands";
$result = mysql_query($sql_brand, $id_link);
if ($result){
while (($row = mysql_fetch_object($result))){
printf ("

\n",
$row->brand_id,$row->brand);

}
mysql_free_result($result);

Re: one long list

am 24.01.2006 10:49:08 von Stefan Rybacki

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

chris schrieb:
> can anyone help?
> I am displaying a list the results are about 60 retailers this will display
> the result in one long list is there a way I can split the results into say
> 3 or 4 columns instead of one long list?
> thanks
>...

Yes it is, but this is a HTML question. Some hints:

- - table
- - div
- - both in combination with or without CSS

Whatever you feel comfortable with.

Regards
Stefan

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (MingW32)

iD8DBQFD1fgUyeCLzp/JKjARAmacAKCznD94pZ3kgyY/DNlVAuRujekrrwCg kb4v
eUdYxNId8O3O8xYQ/IGEY/4=
=QD/F
-----END PGP SIGNATURE-----

Re: one long list

am 24.01.2006 11:23:39 von Shion

chris wrote:
> can anyone help?
> I am displaying a list the results are about 60 retailers this will display
> the result in one long list is there a way I can split the results into say
> 3 or 4 columns instead of one long list?
> thanks
>
function show_brand($columns=2) {
global $id_link;
$sql_brand="select brand_id,brand from brands";
$result = mysql_query($sql_brand, $id_link);
if ($result){
$num_rows=mysql_num_rows($result);
echo "

\n";
for($i=0;$i<$num_rows;$i++) {
if(($i%$columns)==0) {
echo "";
}
$row = mysql_fetch_object($result);
printf(
"\n",
$row->brand_id,$row->brand);
if(($i%$columns)==($columns-1)) {
echo "";
$cols_left=0;
} else {
/* We don't want to break the table */
$cols_left=$columns-($i%$columns);
}
}
if($cols_left) {
for($j=0;$j<$cols_left;$j++) {
echo "\n";
}
}
echo "
%s
 
\n";
}
mysql_free_result($result);

}

Think this should work for you, the code is untested and done it in mozilla,
so don't see if all statements are closed or not. The function can be called
with or without a parameter, if no parameter is used, then it will by default
make two columns.

show_brand(); // two columns
show_brand(5); // five columns

As I don't know how much data you have in your brands table, I have limited
the sql query to only the two columns brand_id and brand, this in case you
have more columns, it's just extra data moved from the sql server to php and
results in more ram usage when executing the php script.

If it don't work, I hope you got the idea how to do it.


//Aho

Re: one long list

am 24.01.2006 21:43:07 von Chris

Many thanks for your help. Tried it out and it works great.

"J.O. Aho" wrote in message
news:43mdhbF1nraj8U1@individual.net...
> chris wrote:
>> can anyone help?
>> I am displaying a list the results are about 60 retailers this will
>> display
>> the result in one long list is there a way I can split the results into
>> say
>> 3 or 4 columns instead of one long list?
>> thanks
>>
> function show_brand($columns=2) {
> global $id_link;
> $sql_brand="select brand_id,brand from brands";
> $result = mysql_query($sql_brand, $id_link);
> if ($result){
> $num_rows=mysql_num_rows($result);
> echo "

\n";
> for($i=0;$i<$num_rows;$i++) {
> if(($i%$columns)==0) {
> echo "";
> }
> $row = mysql_fetch_object($result);
> printf(
> "\n",
> $row->brand_id,$row->brand);
> if(($i%$columns)==($columns-1)) {
> echo "";
> $cols_left=0;
> } else {
> /* We don't want to break the table */
> $cols_left=$columns-($i%$columns);
> }
> }
> if($cols_left) {
> for($j=0;$j<$cols_left;$j++) {
> echo "\n";
> }
> }
> echo "
%s
 
\n";
> }
> mysql_free_result($result);
>
> }
>
> Think this should work for you, the code is untested and done it in
> mozilla,
> so don't see if all statements are closed or not. The function can be
> called
> with or without a parameter, if no parameter is used, then it will by
> default
> make two columns.
>
> show_brand(); // two columns
> show_brand(5); // five columns
>
> As I don't know how much data you have in your brands table, I have
> limited
> the sql query to only the two columns brand_id and brand, this in case you
> have more columns, it's just extra data moved from the sql server to php
> and
> results in more ram usage when executing the php script.
>
> If it don't work, I hope you got the idea how to do it.
>
>
> //Aho