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

我正在尝试计算“ItzBenji”这个词在数据库中列出的次数</ p> \ n

</ p>

但我不知道如何做到这一点:(</ p> \ n

这是一个woocommerce表,“order_items”,我想计算特定优惠券代码的使用次数。我怎么能这样做我试过这个我在网上找到的:</ p>

  $ sql =“select * from wp_woocommerce_order_items”; //选择All 
$ result = mysql_query($ sql);
while($ row = mysql_fetch_assoc($ result)){
if($ row) ['order_item_name'] == itzbenji)
{
echo“test”;
}
}
</ code> </ pre>

但这不起作用:( < / p>

怎么做?让它回显一个像“它被使用了3次”的数字</ p>
</ div>

展开原文

原文

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个回答



  SELECT COUNT(order_item_name)AS rowcount 
FROM wp_woocommerce_order_items
WHERE order_item_name ='itzbenji'
</ code> </ pre>

然后在PHP中,只需 echo $ row ['rowcount']; </ code> </ p>
</ div>

展开原文

原文

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

doubei8168
doubei8168 好的,所以我在phpadmin中得到了这个:gyazo.com/d022c0fdf0aab44bc59fc395b8ea3710但是当我试图回应它时什么都没有? - gyazo.com/7b9ddc804cc82365abcfaa1fb9036b92该页面只是空白?
大约 2 年之前 回复
dongmu9253
dongmu9253 好吧,但只是一个愚蠢的菜鸟问题:我如何解决这个错误? 即时通讯完全是新的PHP。 gyazo.com/4b280ea550aa013783910d0b70cb02b4
大约 2 年之前 回复



您可以使用sql来完成此操作。</ p>

  $ sql =“select 来自wp_woocommerce_order_items“+ 
”的COUNT(order_item_name)“+
”,其中order_item_name ='ItzBenji'“;
$ result = mysql_query($ sql);
echo”使用过的“+ $ result +”times“
</ code> </ pre>

任何人都可以随意纠正我。</ p>
</ div>

展开原文

原文

You could use sql to get this done.

$sql = "select COUNT(order_item_name)" + 
       "from wp_woocommerce_order_items" + 
       "where order_item_name = 'ItzBenji'";
$result = mysql_query($sql);
echo "Its used " + $result + "times" 

Anyone feel free to correct me on this one.

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐