插入数据库表,然后在同一页面中显示该表

时间:2019-03-13 15:23:30

标签: php mysql

您好,我试图弄清楚如何插入然后在一页中显示我的数据库表,但是我迷路了,这里很麻烦,这是我添加的代码

if (isset($_POST['add']) || isset($_POST['delete']))
{
    begin_transaction();

    for ($i = 0, $da = $_POST['begin']; date1_greater_date2($_POST['end'], $da); $i++)
    {
        if (isset($_POST['add']))
            add_budget($da, $_POST['account']);
        else
            delete_budget($da, $_POST['account']);
        $da = add_months($da, 1);
    }
    commit_transaction();

    if (isset($_POST['add']))
        display_notification_centered(_("The Budget has been saved."));
    else
        display_notification_centered(_("The Budget has been deleted."));


}

我的表单显示表,但是我完全失去了在这里做的事情。

start_form();

    $dim = get_company_pref('Company');
    start_table(TABLESTYLE2);
    fiscalyears_list_row(_("Year:"), 'fyear', null);
    gl_all_accounts_list_row(_("Account Code:"), 'account', null);
    submit_row('add', _("Get"), true, '', '', true);

    div_start('budget_tbl');
    start_table(TABLESTYLE2);

这是我添加选择数据库表的功​​能

function add_budget($date_, $account)
{
    $date = date2sql($date_);

        $sql = "INSERT INTO ".TB_PREF."budget (date,
            account) VALUES ('$date',
            ".db_escape($account).")";

    db_query($sql, "The GL budget transaction could not be saved");
}

function get_budget($date_, $account)
{

    $date = date2sql($date_);

        $sql = "SELECT SUM(amount)
        FROM ".TB_PREF."budget
        WHERE account=".db_escape($account);
    if ($date != "")
        $sql .= " AND tran_date >= '$date' ";

    $result = db_query($sql,"No budget");

    $row = db_fetch_row($result);
    return $row[0];
}

0 个答案:

没有答案