作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 shop_product_videos 表:
id |品牌 |产品代码 |链接
每次我加载页面时,它都会使用以下 MySQL 查询获取特定产品的视频:
SELECT link FROM shop_product_videos WHERE brand='$brand' AND product_code='$product_code' LIMIT 1
并显示它。
示例:
$brand = "Samsung";
$product_code = 111;
43 | Samsung | 111 | youtube.be/111222333
因此,如果我的页面加载名为“Samsung”的产品,并且它的“product_code”为“111”,它将显示数据库中该行的视频链接。
我想更新我的函数,以适应只有品牌名称但表中没有产品代码(空/空)的情况,并且我想显示该产品的“常规视频”(以及所有项目)有“三星”作为品牌)。
想要的结果示例:
$brand = "Samsung";
$product_code = 777;
43 | Samsung | 111 | youtube.be/111222333
44 | Samsung | | youtube.be/444555666
运行查询时,我将获得视频的第二行 (id 44),因为它没有找到与 777 product_code
完全匹配的内容
最佳答案
简单使用OR
SELECT link FROM shop_product_videos
WHERE brand='$brand'
AND (product_code is null or product_code='$product_code')
LIMIT 1
更新1:
SELECT link FROM shop_product_videos
WHERE brand='$brand'
AND ( product_code='$product_code' or product_code='' or product_code is null) LIMIT 1
关于php - [MySQL] : Get product row - if doesn't exist by brand & product_code - get only by brand where product_code is empty,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45564861/
我有一个 shop_product_videos 表: id |品牌 |产品代码 |链接 每次我加载页面时,它都会使用以下 MySQL 查询获取特定产品的视频: SELECT link FROM sh
我正在尝试从如下所示的查询字符串中获取数据: http://127.0.0.1:8000/product/controller/php?ids[]=[product_code]1INSAZE 如果我这
我是一名优秀的程序员,十分优秀!