<div style="width:800px;">

<? 
$model_insert = '';
$menu_insert = '';
$permission_insert = '';

while($row = $this->templates->Assoc()){

	unset($column);
	unset($values);

	foreach($row as $k => $v){

		$v = addslashes(htmlspecialchars($v));
		$column .= $column ? ", `".$k."`" : "`".$k."`";
		$values .= $values ? ", '".$v."'" : "'".$v."'";
	}
	$model_insert .= "INSERT INTO `templates` (".$column.") <br>VALUES (".$values.");<br/>";
	if($this->menus->Numrows > 0){

		while($row = $this->menus->Each()){

			unset($column);
			unset($values);

			foreach($row as $k => $v){

				$v = addslashes(htmlspecialchars($v));
				$column .= $column ? ", `".$k."`" : "`".$k."`";
				if($k == 'id')
					$values .= isset($values) ? ", 0" : "0";
				else
					$values .= isset($values) ? ", '".$v."'" : "'".$v."'";
			}
			$menu_insert .= "INSERT INTO `menus` (".$column.") <br>VALUES (".$values.");<br/>";
		}
	}
	if($this->permissions->Numrows > 0){

		while($row = $this->permissions->Each()){

			unset($column);
			unset($values);

			foreach($row as $k => $v){

				$v = addslashes(htmlspecialchars($v));
				$column .= $column ? ", `".$k."`" : "`".$k."`";
				if($k == 'id')
					$values .= isset($values) ? ", 0" : "0";
				else
					$values .= isset($values) ? ", '".$v."'" : "'".$v."'";
			}
			$permission_insert .= "INSERT INTO `permissions` (".$column.") <br>VALUES (".$values.");<br/>";
		}
	}
}


echo $model_insert.'<br/><br/>';
if($menu_insert)
	echo $menu_insert.'<br/><br/>';
if($permission_insert)
	echo $permission_insert.'<br/><br/>';
?>

</div>