function makeTables($guests, $seated = []) { if (!empty($guests)) { $return = array(); for ($i = count($guests) - 1; $i >= 0; $i--) { $newGuests = $guests; $newSeated = $seated; list($city) = array_splice($newGuests, $i, 1); array_unshift($newSeated, $city); $return = array_merge($return, makeTables($newGuests, $newSeated)); } } else { $return = array($seated); } return $return; }
//insert data into participant interactions table $sql = "INSERT INTO p" . $pid . "_interactions (timestp, interaction, page, set) VALUES (:timestp, :interaction, :page, :set);"; try { $stmt = $dbh->prepare($sql); $stmt->bindParam(':timestp', $tmsp); $stmt->bindParam(':interaction', $interaction); $stmt->bindParam(':page', $page); $stmt->bindParam(':set', $set); $stmt->execute(); } catch (PDOException $e) { echo 'SQL Query: ', $sql; echo 'Error: ' . $e->getMessage(); } } if (isset($post_data["pages"])) { makeTables($dbh, $post_data); } else { updateTables($dbh, $post_data); } } } //e-mail data if e-mail is set up if (isset($smtphost, $smtpport, $euser, $epass, $toaddr, $subject, $message)) { //variables of great social and political import $pid = $post_data["pid"]; //check for directory and create if not exists if (!file_exists("../participants")) { mkdir("../participants", 0777, true); } //check for file and create with column headers if not exists $filepath = "../participants/p" . $pid . "_interactions.csv";
<?php require_once __DIR__ . '/common.php'; $guests = array_keys($happinesses); foreach ($guests as $guest) { $happinesses[$guest]['me'] = $happinesses['me'][$guest] = 0; } $tables = makeTables(array_keys($happinesses)); echo 'Answer: ' . getMaxHappiness($tables, $happinesses);