Page 1 of 1

display in column n rows

Posted: Mon Jul 30, 2007 10:03 pm
by kanchan
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...

Posted: Mon Jul 30, 2007 10:07 pm
by feyd
Sorry, I'm not sure what you're asking for.

Posted: Tue Jul 31, 2007 11:35 am
by yacahuma
feyd | Please use

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 want

Code: 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[]='&nbsp;';
	$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);

feyd | Please use

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]

solution

Posted: Tue Jul 31, 2007 11:41 am
by assgar
Hi

Thanks for the responses.

The problem is solved.

I removed the explicitly set the table height.
This prevents the rows from filling
the available height.

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";

?>

Posted: Tue Jul 31, 2007 1:57 pm
by kanchan
feyd wrote:Sorry, I'm not sure what you're asking for.
ok let me make you clear .. suppose i have many lists in my table(e.g : images n its details) and i need the code to display them like in the picture i posted here below...

Image

so can you please help me out?

Posted: Tue Jul 31, 2007 6:41 pm
by feyd
Take a look at the first two threads linked from Useful Posts.

Posted: Tue Jul 31, 2007 10:02 pm
by kanchan
didn't get you guys... as i am not a newer to PHP, i need the code man... i need to show the items of table as i shown above in the pic.. :(

Posted: Tue Jul 31, 2007 10:11 pm
by feyd
As I said, take a look at the first two threads linked from Useful Posts.