display in column n rows

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kanchan
Forum Commoner
Posts: 80
Joined: Tue Nov 30, 2004 12:03 pm

display in column n rows

Post 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...
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Sorry, I'm not sure what you're asking for.
User avatar
yacahuma
Forum Regular
Posts: 870
Joined: Sun Jul 01, 2007 7:11 am

Post 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]
assgar
Forum Commoner
Posts: 46
Joined: Fri Apr 20, 2007 9:00 pm

solution

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

?>
kanchan
Forum Commoner
Posts: 80
Joined: Tue Nov 30, 2004 12:03 pm

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Take a look at the first two threads linked from Useful Posts.
kanchan
Forum Commoner
Posts: 80
Joined: Tue Nov 30, 2004 12:03 pm

Post 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.. :(
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

As I said, take a look at the first two threads linked from Useful Posts.
Post Reply