Page 1 of 1

Dynamic table

Posted: Fri Jan 31, 2003 9:54 pm
by dstefani
I'm trying to build a dynamic table that will have varying amounts data.
I've got it working to a point, but I'm at a block.

I want the row number to always be 10 max.
For example, I may have 3 cols of 10 rows and the last col only has 4 rows worth of data. I will need to fill those cells with  .

The amounts of cols will vary depending on the users query.
It would have to be completely dynamic.

Have you built something like this before?
I could use your incite. I have the feeling that it's right there on the tip of my brain. I hope I explained this clear enough.

Thanks,
Don

Posted: Fri Jan 31, 2003 11:09 pm
by Stoker
Does each piece of data have to be in its own cell of the same table?
I solved such columnizing before byt taking the amount of data and divide by max-rows to find out how many columns, then make a column-loop, and in each column create yet another table with a single column and the amount of rows, in the last main column you just add as many rows as there is data left without the need for whitespacing empty cells..

Posted: Sat Feb 01, 2003 8:26 am
by dstefani
I guess I answered my own question.
I don't know if I'll need to worry about empty cells right now, but here's what I came up with for building a spreadsheet type of table in PHP.
This is not generated from MySQL yet, but you can probably see where I'm going with this. I built this from scratch to excercise my brain, it was fun. Still a rookie, but working on it.

- Don

Code: Select all

<?

$total_cells = 500;// would be recordset
$row_count = 10; // rows for my table
$col_count = $total_cells / $row_count; // cols I'll have



print "<table cellpadding="4" border=1>\n";
$row_incrementer = 1;
$col_lable = 1;
for($r = 1; $r <= $row_count; $r++)// build rows
&#123;
	
	print "<tr>\n";
	for($c = 0; $c < $col_count; $c+=10)// build cols
	&#123;
		print "<td>$col_lable</td>";
		$col_lable+=10;
	&#125;
	print "</tr>\n";
	$row_incrementer++; // need a int to add to my next row
	$col_lable = $row_incrementer;// my row increments by 1 each time through
	
&#125;
print "</table>";

?>