You are here: Re: one long list « PHP SQL « IT news, forums, messages
Re: one long list

Posted by J.O. Aho on 01/24/06 12:23

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 "<table>\n";
for($i=0;$i<$num_rows;$i++) {
if(($i%$columns)==0) {
echo "<tr>";
}
$row = mysql_fetch_object($result);
printf(
"<td><ahref=\"./?action=list&brand_id=%s\"><b>%s</b></a></td>\n",
$row->brand_id,$row->brand);
if(($i%$columns)==($columns-1)) {
echo "</tr>";
$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 "<td>&nbsp;</td>\n";
}
}
echo "</table>\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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация