F1 = $f1; $this->F2 = $f2; } }; function load_data() { $con = new mysqli('127.0.0.1', '', '', 'Test'); if(mysqli_connect_errno()) die(mysqli_connect_error()); if($stmt = $con->prepare('SELECT f1,f2 FROM t1')) { $stmt->execute(); $stmt->bind_result($f1, $f2); $res = array(); while ($stmt->fetch()) { $res[] = new T1($f1, $f2); } $stmt->close(); } else { die($con->error); } $con->close(); return $res; } function format_data($data, $all_template, $one_template) { $rows = ''; foreach($data as $t1) { $rows .= sprintf($one_template, $t1->F1, $t1->F2); } $html = sprintf($all_template, $rows); return $html; } $data = load_data(); $all_template = "\r\n" . "\r\n" . "%s" . "
f1f2
\r\n"; $one_template = "%d%s\r\n"; echo format_data($data, $all_template, $one_template); ?>