Scripts

Table Generator

Dit script heb ik geschreven met een doel, dus de code is niet gelijk bruikbaar. Maar zo is wel makkelijk te zien hoe deze functie werkt!

table-generator
<?php
$ppp = 2;
$col = 4;
$td_title = array();
$td_picture = array();
$td_descript = array();
$id = array();
$counter = 0;
while($counter <= 9) {
	array_push($td_title, 'naam'.$counter);
	array_push($td_picture, 'picture'.$counter);
	array_push($td_descript, 'description'.$counter);
	array_push($id, 'id'.$counter);
	$counter++;
}
$waarden = count($td_title);
$minrijen = ceil($waarden/$col);
$maxrijen = ceil($ppp/$col);
if($minrijen <= $maxrijen) {
	$rijen = $minrijen;
}
else {
	$rijen = $maxrijen;
}
echo "\n".'<table width="100%" border="1" cellspacing="0" cellpadding="0">';
echo "\n\t".'<tr>';
$cntr = 0;
for($i = 0; $i <= $rijen--; $i++) {
	for($i2=0; $i2 <= $col-1; $i2++) {
		echo "\n\t\t".'<td>';
		if(isset($td_title[($i*$col)+$i2]) && ($i*$col)+$i2 < $ppp) {
			echo $td_title[($i*$col)+$i2];
		}
		echo '</td>';
	}
	echo "\n\t".'</tr>';
	echo "\n\t".'<tr>';
	echo "\n\t\t".'<td>&nbsp;</td>';
	echo "\n\t".'</tr>';
	echo "\n\t".'<tr>';
	$cntr++;
}
echo "\n\t\t".'<td></td>';
echo "\n\t".'</tr>';
echo "\n".'</table>';
?>

Reacties

0
Nog geen reacties.