Example #1
0
/**
 * Renders the next profile to view.
 */
function render_next()
{
    //find current viewnum
    $viewNum = CS50::query("SELECT viewNum FROM users WHERE id = ?", $_SESSION["id"]);
    $viewnum = $viewNum[0]["viewNum"];
    //find id of last viable profile
    $last = CS50::query("SELECT MAX(id) FROM users");
    //increment viewnum to next viable profile
    do {
        CS50::query("UPDATE users SET viewNum = viewNum + 1 WHERE id = ?", $_SESSION["id"]);
        $viewnum++;
        if ($viewnum > $last[0]["MAX(id)"]) {
            apologize("You've seen e'rybody!");
            break;
        }
    } while (count(CS50::query("SELECT * FROM users WHERE id = ?", $viewnum)) == 0 || $viewnum == $_SESSION["id"]);
    // render homepage; show new profile.
    render("home.php", ["title" => "home", "profile" => prof_lookup($viewnum)]);
}
Example #2
0
<?php

// configuration
require "../includes/config.php";
// if user reached page via GET (as by clicking a link or via redirect)
if ($_SERVER["REQUEST_METHOD"] == "GET") {
    render("prof_form.php", ["title" => "Edit"]);
} else {
    if ($_SERVER["REQUEST_METHOD"] == "POST") {
        //insert new interest into interests database
        CS50::query("INSERT INTO interests (user_id, interest) VALUES(?, ?)", $_SESSION["id"], $_POST["interest"]);
        // render updated profile
        render("prof_page.php", ["title" => "Profile", "profile" => prof_lookup($_SESSION["id"])]);
    }
}
Example #3
0
<?php

// configuration
require "../includes/config.php";
// if user reached page via GET (as by clicking a link or via redirect)
if ($_SERVER["REQUEST_METHOD"] == "GET") {
    $viewnum = CS50::query("SELECT viewNum FROM users WHERE id = ?", $_SESSION["id"]);
    $last = CS50::query("SELECT MAX(id) FROM users");
    if ($viewnum[0]["viewNum"] > $last[0]["MAX(id)"]) {
        apologize("You've seen e'rybody!");
    }
    // render homepage
    render("home.php", ["title" => "home", "profile" => prof_lookup($viewnum[0]["viewNum"])]);
}
Example #4
0
<?php

// configuration
require "../includes/config.php";
// if user reached page via GET (as by clicking a link or via redirect)
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $matchlook = CS50::query("SELECT id FROM users WHERE username = ?", $_POST["matchname"]);
    // render homepage
    render("match_profile.php", ["title" => "match_prof", "profile" => prof_lookup($matchlook[0]["id"]), "match" => $matchlook[0]["id"]]);
}