display in column n rows
Posted: Mon Jul 30, 2007 10:03 pm
can you guys please provide me the code to display the numbers of items of a certain table in column and in rows in 4x3.. i mean in 4 column n 3 rows...?? please help me out...
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
I am not sure if this is what you need but this functions displays an array of data in table form. You just tell it how many columns you wantCode: Select all
function arrayToTable($arr,$cols)
{
$arrcnt = count($arr);
if ($arrcnt==0) return '';
$rows = ceil($arrcnt/$cols);
$tableArr = array();
for($i=0;$i<( ($rows*$cols) - $arrcnt);$i++)
$tableArr[]=' ';
$tableArr=array_merge($arr, $tableArr);
$str = '';
$line = '';
$cnt=1;
foreach($tableArr as $cell)
{
$str .= "<td>$cell</td>";
if ($cnt++ == $cols)
{
$line .= "<tr>$str</tr>";
$str = '';
$cnt=1;
}
}
return '<table width="100%">' . $line . '</table>';
}
$arr = array(4,5,6,7,7,87,"HELLO","BLLLA");
arrayToTable($arr,3);Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]Code: Select all
<?php
echo "<table width=\"100%\" border=\"0\">";
echo"<tr align=\"center\" bgcolor=\"#FFFFFF\">";
echo" <td width=\"100%\" >
<div id=\"Layer2\" style=\"position:absolute; width:100%; height:100px; z-index:2; left: 8px; top: 310px;\">
<div id=\"scroll-box2\" style=\"overflow: auto; float: left; width: 100%; height: 240px; margin: 5px; \">\n";
//table begins
echo "<table width=\"98%\" height=\"\" left =\"4\" border=\"0\" font face =\"arial\">\n";
?>