PHP SQL 语句使用 REGEXP 获取多个值



如何使用 REGEXP 从数组$vall中获取多个数据。

我引用了一个示例代码:PHP sql 语句,其中子句到多个数组值

部分示例数据:CGCG-0025-0,CGCR-0003-0,CGRQ-0163-0

foreach ($list as $value) // this $list is from another array
{
    $part = $value[3];
    $vall[] = $value[3];  // $list1 is an empty array
}
$partnumber =[];
foreach($vall as $v)
{
    $partnumber[] = "*.".$v.".*";
    print_r(array_values($partnumber));   // these are some of the values Array ( [0] => *.CGCG-0025-0.* ) Array ( [0] => *.CGCG-0025-0.* [1] => *.CGCG-0025-0.* ) Array ( [0] => *.CGCG-0025-0.* [1] => *.CGCG-0025-0.* [2] => *.CGCR-0003-0.* )
}
foreach($partnumber as $x)
{
    echo '<br>'.$partnumber; // shows 'Array' on each lines 
}
$fsql="select * from Error where RptDatime = 201706091000 and partnumber REGEXP  '".implode("|",$partnumber)."'";
//example 1 $fsql="select * from MPdError where RptDatime = 201706091000 and partnumber = ('CGRQ-0057-0') ";
//example 1 shows the correct data but i need multiple partnumber
$getResults = $conn->prepare($fsql);
$getResults->execute();
$results = $getResults->fetchAll(PDO::FETCH_BOTH);
foreach($results as $row)
{
    $mac = $row['Machine'];
    $id = $row['Id'];
    echo '<br><br><br>ID:'.$id.'<br>Machine Number :'.$mac;
}

尽管这可能不是一个好的解决方案,因为它包含巨大的安全风险,但我仍然会根据上述需要发布它。

对于设计中不复杂的数据,不需要 REGEXP。

$fsql = "select * from Error where RptDatime = 201706091000 and partnumber in ('" . implode("','", $vall) . "');"

最新更新