douzhanshen0657 2010-02-22 05:05
浏览 18
已采纳

如何将两个变量与查询中的id表值进行比较?

switch($_GET["action"])
  {
   case "add_item":
  {
    AddItem($_GET["ids"], $_GET["qty"]);
    ShowCart();
    break;
  }
default:
 {
   ShowCart();
 }

function AddItem($itemId, $qty){


   $result = mysql_query("SELECT COUNT(*) FROM cart WHERE cookieId = '" . GetCartId() . "' AND id = $itemId");

  $row = mysql_fetch_row($result);
  $numRows = $row[0];

if($numRows == 0)
{

Can you see the AddItem Switch and case function I want to add $_POST["idc"] just like below.

AddItem($_GET["ids"], $_POST["idc"], $_GET["qty"]);       

Then in the function AddItem below the AddItem function inside the Switch function I will need to add another argument since there are three inside the Switch function. $itemId, $itemIdII and $qty

function AddItem($itemId, $itemIdII, $qty){ 

}

Notice that I have added $itemIdII to the AddItem function since I have added ,$_POST["idc"] in the Switch function.

Now the question

How can I compare $itemId and $itemIdII to the id in the query? Right now its like

  AND id=$itemId

But how could I add $itemIdII to the query to compare it.

  AND id=$itemId OR $itemIdII     

Thanks!

  • 写回答

1条回答 默认 最新

  • doulongsi1831 2010-02-22 05:07
    关注
    AND id IN ($itemId, $itemIdII)
    

    or

    AND (id=$itemId OR id=$itemIdII)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于超局变量获取查询的问题
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集
  • ¥15 在启动roslaunch时出现如下问题
  • ¥15 汇编语言实现加减法计算器的功能
  • ¥20 关于多单片机模块化的一些问题
  • ¥30 seata使用出现报错,其他服务找不到seata
  • ¥35 引用csv数据文件(4列1800行),通过高斯-赛德尔法拟合曲线,在选取(每五十点取1点)数据,求该数据点的曲率中心。
  • ¥20 程序只发送0X01,串口助手显示不正确,配置看了没有问题115200-8-1-no,如何解决?