function get_activity_data($num) { $db = new MyDB(); if (!$db) { echo $db->lastErrorMsg(); } else { } $sql = <<<EOF SELECT * FROM Activity ORDER BY id LIMIT {$num},3; EOF; $arrayList[] = array(); $ret = $db->query($sql); $index = 0; while ($row = $ret->fetchArray(SQLITE3_ASSOC)) { $authorId = $row['authorId']; $authorName = get_authorName($db, $authorId); $title = $row['title']; $target = $row['target']; $content = $row['content']; $id = $row['id']; $menbers = get_members($db, $id); $arrayList[$index] = [$title, $target, $content, $authorName, $id, $menbers]; $index++; } $db->close(); return $arrayList; }
function show_activity($last, $amount) { $db = new MyDB(); if (!$db) { echo $db->lastErrorMsg(); } else { } $userName = $_COOKIE['username']; $userId = get_userId($db, $userName); $sql = <<<EOF SELECT * FROM Advice WHERE toUserId={$userId} ORDER BY id DESC LIMIT '{$last}','{$amount}'; EOF; $ret = $db->query($sql); while ($row = $ret->fetchArray(SQLITE3_ASSOC)) { $authorId = $row['authorId']; $authorName = get_authorName($db, $authorId); if ($authorName != null) { $sayList[] = array('title' => "标题:" . $row['title'], 'content' => "建议内容: " . $row['content'], 'authorName' => "提出者: " . $authorName); } } echo json_encode($sayList); $db->close(); }