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'];

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据