使用php中的两个implode值获取数据

时间:2018-05-29 10:48:09

标签: php mysqli pdo

我正在尝试从数据库中获取值,其值为1列,

我的桌子:

╔════╦═══════════════╦═══════╗
║ id ║  Community    ║ name  ║
╠════╬═══════════════╬═══════╣
║  1 ║ Jeff, Atwood  ║ test1 ║
║  2 ║ Geoff Dalgas  ║ test2 ║
╚════╩═══════════════╩═══════╝

我的sql语句

    $testvalue = 'Jeff, Dalgas';
    foreach ($testvalue as $key) {
         $this->query("SELECT id FROM users WHERE Community LIKE :key");
         $this->bind(':key', '%'.$key.'%');
         $row3 = $this->resultSet();
var_dump($row3);
    }

仅检查第一个值,而不是在$testvalue中打印第二个值我想检查$testvalue中的每个值是否与列提取详细信息匹配

2 个答案:

答案 0 :(得分:0)

试试这个:

$testvalue = array('jeff', 'dalgas');

答案 1 :(得分:0)

不确定,但也许你可以试试

    $testvalue = explode(",", 'Jeff, Dalgas');
    $conditions = $parameters = $parameters_type = array();

    foreach ($testvalue as $key) {
        $conditions[] = ' FIND_IN_SET(?, "Community") ';
        $parameters[] = $key;
        $parameters_type[] = 's';
    }

    $where = implode(" OR ", $conditions);

    $this->query("SELECT id FROM users WHERE $where ");
    $parameters_type = implode("",$parameters_type);
    $this->bind_param($parameters_type, $parameters);
    $row3 = $this->resultSet();