prepare($sql) or die(mysqli_error()); $stmt->execute() or die(mysqli_error()); $rs = $stmt->get_result(); $res = array(); while($row = $rs->fetch_array(MYSQLI_ASSOC)) { $res[] = $row; } $stmt->close(); $con->close(); return $res; } function display_header($grp, $vals) { echo "\r\n"; echo "\r\n"; echo "\r\n"; echo "\r\n"; echo "\r\n"; } function display_group_item($item) { echo "\r\n"; } function display_value_item($item) { echo "\r\n"; } function display_footer() { echo "
$grp$vals
$item$item
\r\n"; } function show_horizontal($data, $grpfld, $valfld1, $valfld2) { $prev = ''; $vals = array(); foreach($data as $res) { if($res[$grpfld] != $prev) { if(count($vals) > 0) { display_value_item(implode(',', $vals)); $vals = array(); } display_group_item($res[$grpfld]); $prev = $res[$grpfld]; } $vals[] = ($res[$valfld1] . ':' . $res[$valfld2]); } if(count($vals) > 0) { display_value_item(implode(',', $vals)); $vals = array(); } } function show_rounds() { $data = get_results('SELECT round, player, point FROM whist ORDER BY round, player'); display_header('Round', 'Result'); show_horizontal($data, 'round', 'player', 'point'); display_footer(); } function show_players() { $data = get_results('SELECT round, player, point FROM whist ORDER BY player, round'); display_header('Player', 'Result'); show_horizontal($data, 'player', 'round', 'point'); display_footer(); } show_rounds(); show_players(); ?>