doupu9251 2018-06-05 15:14
浏览 126

过滤数据库行中的单词,并对其进行计数

I'm trying to count how many times the word "ItzBenji" is listed in the database

enter image description here

But i have no clue what so ever, on how to do it :(

It's a woocommerce table, of "order_items" and i want to count how many times the specific Coupon code is used. How can i do that I tried this i found online:

$sql = "select * from wp_woocommerce_order_items"; //Select All
$result = mysql_query($sql);
while($row = mysql_fetch_assoc($result)) { 
    if($row['order_item_name'] == itzbenji) 
    {
         echo "test";
    }
}

But that did not work :(

How to do it? And make it echo a number like "It is used 3 times"

  • 写回答

2条回答 默认 最新

  • dsg24156 2018-06-05 15:20
    关注
    SELECT COUNT(order_item_name) AS rowcount
    FROM wp_woocommerce_order_items
    WHERE order_item_name = 'itzbenji'
    

    Then in your PHP, just echo $row['rowcount'];

    评论

报告相同问题?

悬赏问题

  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?