【问题标题】:How to use strpos with Medoo query如何在 Medoo 查询中使用 strpos
【发布时间】:2017-03-19 07:56:33
【问题描述】:

我写了这个函数来检索基于 STRPOS 的统计中记录的网站链接的主页,但是 Medoo 抛出了一个错误。

function getSiteAuthor($string) {
if ($string) {
    $result = db::query("SELECT id, http FROM users WHERE (strpos(http, '$string') != false) ");
        foreach ($result as $row) {
            return $row['id'];
        }
}

}

http 可能是“http://example.com”,而 $string 可能是“http://example.com/somePage/”。所以我正在寻找包含在 $string

中的 http 的位置

错误是“strpos not found in table”。

这可以使用 strpos 完成,还是应该使用 LIKE,如果可以,如何编码。

【问题讨论】:

    标签: medoo


    【解决方案1】:

    在这里使用 LIKE 可以在“http”中找到“$string”来生成网站所有者的“id”。只需在上面的代码中替换这一行。

    $result = db::query("SELECT id, http FROM users WHERE http LIKE '%$string%' ");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-04
      • 1970-01-01
      • 2012-06-19
      • 1970-01-01
      • 2015-08-16
      • 2023-03-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多