Example #1
0
    if ($action == "save" && $id && $name) {
        $sql = "UPDATE restaurants SET Name = '{$name}', Note = '{$note}' WHERE id='{$id}' LIMIT 1;";
        $db->query($sql);
        forward("restaurants.php");
    } else {
        if ($action == "add" && $name) {
            $sql = "INSERT INTO restaurants (Name, Note) VALUES ('{$name}', '{$note}');";
            $db->query($sql);
            forward("restaurants.php");
        }
    }
}
if ($action == "edit" && $id) {
    $sql = "SELECT Name, Note FROM restaurants WHERE id='{$id}' LIMIT 1;";
    $db->query($sql);
    if ($row = $db->fetchrow()) {
        list($name, $note) = $row;
        $button = "Save";
        $action = "save";
        $task = "Edit";
        $idInput = '<input type="hidden" name="id" value="' . $id . '"/>';
    }
}
if (!$name || !$task || !$button) {
    $button = "Create";
    $action = "add";
    $task = "Add New";
    $idInput = "";
}
$db->query("SELECT ID,Name,Note from restaurants ORDER BY Name DESC");
$body .= "<table><thead><tr><td>Name</td><td>Note</td><td>Delete</td></tr></thead><tbody>";
Example #2
0
function getRestaurantList()
{
    $db = new DB();
    $db->query("SELECT ID, Name FROM restaurants;");
    while (list($id, $name) = $db->fetchrow()) {
        $result[$id] = $name;
    }
    return $result;
}