dtrpv60860 2016-02-28 15:56
浏览 64

如何更新一整天的数据库值

I am building a web application, for travelling. I have managed to get users to be able to insert how much they have spent on each category (i.e. travel, accomodation, food, etc) into the database once from a form. However, I want them to be able to contiously add to the total value of each category for just that day using the same form, and then everyday have a new total for each category as well. I'm not quite sure how I would do that at the moment. Here is my code so far for inserting the values into the database from my form (which works):

if(isset($_POST['addinfo_button'])){
    $Food = $_POST['food'];
    $Transport = $_POST['transport'];
    $Accom = $_POST['accomodation'];
    $Entertain = $_POST['entertainment'];
    $Souvenir = $_POST['souvenirs'];    
    $Misc = $_POST['miscellaneous'];    
    $Date = date("Y-m-d");
    $Trip_id;
        $sql = "SELECT * FROM trips WHERE id =$user_id_session AND date1 <= '$Date' && date2 >= '$Date'";
        $records = mysql_query($sql); 
        while($trip=mysql_fetch_assoc($records)){
        $Trip_id = $trip['trip_id'];    
        }
    $foreignkey = $user_info['id'];

    $sql = $con->query("INSERT INTO todays_spend (food, transport, accomodation, entertainment, souvenirs, miscellaneous,date, trip_id, id)Values('{$Food}', '{$Transport}', '{$Accom}', '{$Entertain}','{$Souvenir}', '{$Misc}','{$Date}','{$Trip_id}','{$foreignkey}')"); 

    header('Location: budgetbuddy.php');    
}

Would I have to do something similar to this? or modify this one slightly?

  • 写回答

1条回答 默认 最新

  • dsla94915 2016-02-28 16:27
    关注

    Could not write code for you. But I can give you an Idea how you can achieve this having only one form. Create a table with your needs.I mean your entertainement, food, etc along with their name and Id. If you can make user enter their name or anything that users can uniquely identified. Then things go easier. When a user enter their how much they spent insert into table along with their name or identifier. Next time same user enter details simply find if already user has anything updated on same day , if user added anything before simply update the table by adding previously existing values to new values. Update them. Now you easily even find how much each user spent on particuler catogery.Hope it helps. Thank you.

    评论

报告相同问题?

悬赏问题

  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画