Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/solr/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 循环中的strpos($array,$check)_Php_While Loop_Wildcard - Fatal编程技术网

Php 循环中的strpos($array,$check)

Php 循环中的strpos($array,$check),php,while-loop,wildcard,Php,While Loop,Wildcard,我使用While循环遍历sql查询的结果。在While循环中,我使用for循环在数组中执行“通配符搜索”。现在我正在取得很多成果。目标是将SQL查询中$social\u result中的行与数组$email\u rank\u results的内容进行比较,如果找到,则向$social\u cnt变量添加1。如果有人能给我一些关于如何更改代码以实现这一点的建议,我将不胜感激 $email\u rank\u results数组包含“google.com”、“facebook.com”、“linked

我使用While循环遍历sql查询的结果。在While循环中,我使用for循环在数组中执行“通配符搜索”。现在我正在取得很多成果。目标是将SQL查询中
$social\u result
中的行与数组
$email\u rank\u results
的内容进行比较,如果找到,则向
$social\u cnt
变量添加1。如果有人能给我一些关于如何更改代码以实现这一点的建议,我将不胜感激

$email\u rank\u results
数组包含“google.com”、“facebook.com”、“linkedin.com”、“twitter.com”等值

$social_结果
包含“pages.facebook.com”、“nb linkedin.com”、“plus.google.com”等值

这是我的密码:

$socialSQL= sprintf("SELECT name FROM class_social");
$social_result = mysql_query($socialSQL) or die ("Error in query: $socialSQL " . mysql_error());

while($row=mysql_fetch_row($social_result)) {
$check = $row[0];
$max = count($email_rank_results);
for($x = 0; $x < $max; $x++)
{

if (stripos($email_rank_results[1],$check) !== false)
{
    $social_cnt = $social_cnt+1;
}
}
}
$socialSQL=sprintf(“从类_social中选择名称”);
$social\u result=mysql\u query($socialSQL)或die(“查询中的错误:$socialSQL.mysql\u Error());
while($row=mysql\u fetch\u row($social\u result)){
$check=$row[0];
$max=计数($email\u rank\u results);
对于($x=0;$x<$max;$x++)
{
if(stripos($email\u rank\u results[1],$check)!==false)
{
$social\u cnt=$social\u cnt+1;
}
}
}
  • 你把草堆和针混在一起了
  • 在foreach循环中,只比较数组$email\u rank\u results的第一个元素
  • 替换:

    stripos($email_rank_results[1], $check)
    

    或者简单地使用每个循环

    foreach($email_rank_results as $email_rank_result)
    {
    
      if (stripos($check, $email_rank_result) !== false)
      {
        $social_cnt = $social_cnt+1;
      }
    }
    

    在上面我假设$email_rank_results是平面数组,即数组('google.com','facebook.com')

    那么,到目前为止,您的代码有什么问题?为什么不根据搜索条件限制查询?为什么用PHP进行“搜索”呢?代码的问题是我收到的结果太多了。代码中有一个逻辑错误,而不是语法错误Ziollek,这就成功了。我想我是因为在代码上花了好几个小时才瞎了眼
    foreach($email_rank_results as $email_rank_result)
    {
    
      if (stripos($check, $email_rank_result) !== false)
      {
        $social_cnt = $social_cnt+1;
      }
    }