duandu2159 2012-11-22 11:23
浏览 15
已采纳

如果收到x则更新列,否则更新y

If I have a table with 3 columns: id,column1,column2. If i want to update column1 just when receiving "column1" parameter in URL request otherwise update column2 when receiving "column2" parameter in URL adress. Is that possible? I made that but i think that's not correct:

$sql= "UPDATE people SET 
answer_yes= '$answer_yes'+1,
answer_no='$answer_no'+1";

Thank you for helping.

EDIT: Now that is working (based on Richard Vivian answer)

    If($answer_yes==1)
{

    $sql= "UPDATE people SET answer_yes= answer_yes +1"or die(mysql_error());
    mysql_query($sql);
    }
    else if ($answer_no==0)
    {
    $sql= "UPDATE people SET answer_no= answer_no+1" or die(mysql_error());
    mysql_query($sql);
    }
  • 写回答

3条回答 默认 最新

  • doushi1960 2012-11-22 11:31
    关注

    You can create 2 SQL statement options:

    If($answer_yes)
    {
    $sql= "UPDATE people SET answer_yes= '$answer_yes'+1"
    }
    else
    {
    $sql= "UPDATE people SET answer_no= '$answer_no'+1"
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作