dsfhd78978 2013-03-26 12:38
浏览 82
已采纳

如何将布尔参数传递给php函数?

When I try to get the value of "sold" and "featured" I get nothing. What am I doing wrong?

function list_products($sold = false, $featured = false) {
    global $link;
    $result = mysqli_query($link, "SELECT * FROM products product JOIN images image ON product.id = image.product_id WHERE product.main_image = image.id AND product.sold = $sold AND product.featured = $featured") or die(mysqli_error($link));
}

list_products(false, true);

Edit: If I try to echo $sold or $featured, they are blank. A 1 or 0 should show.

  • 写回答

2条回答 默认 最新

  • dsfdsfdsfdsf1223 2013-04-08 09:13
    关注

    In your case you can give the arguments numeric values when calling the function (you want to use them as numeric in your query anyway).

    Try:

    function list_products($sold = 0, $featured = 0) {
        global $link;
        $result = mysqli_query($link, "SELECT * FROM products product JOIN images image ON product.id = image.product_id WHERE product.main_image = image.id AND product.sold = $sold AND product.featured = $featured") or die(mysqli_error($link));
    }
    
    list_products(0, 1);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥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,时序沉降图怎么画