0
<?php function ss($s1, $s2, $s3, $s4, $s5, $s6) {
  $sonucArray = array("alti" => 0, "bes" => 0, "dort" => 0, "uc" => 0, "iki" => 0);
  $sayiArray = array($s1, $s2, $s3, $s4, $s5, $s6);
  $sayiArraySql = join(',',$sayiArray);  
  $query = mysql_query("select * from loto where 
                                  s1 in ($sayiArraySql) or
                                  s2 in ($sayiArraySql) or
                                  s3 in ($sayiArraySql) or
                                  s4 in ($sayiArraySql) or
                                  s5 in ($sayiArraySql) or
                                  s6 in ($sayiArraySql)");

  while ($record = mysql_fetch_array($query)) {
      $controlArray = array($record["s1"],$record["s2"],$record["s3"],$record["s4"],$record["s5"],$record["s6"]);
      $diffArray = array_diff($sayiArray,$controlArray);

      if (count($diffArray) == 0)
          $sonucArray["alti"]++;
      else if (count($diffArray) == 1)
          $sonucArray["bes"]++;
      else if (count($diffArray) == 2)
          $sonucArray["dort"]++;
      else if (count($diffArray) == 3)
          $sonucArray["uc"]++;
      else if (count($diffArray) == 4)
          $sonucArray["iki"]++;      
  }

  return $sonucArray;
}

mysql_fetch_array; 使用过多的 CPU 且速度不快!

“s1-s2-s3-s4-s5-s6”是整数。

相反,什么应该是代码?我知道php不足。有人建议我使用“mysql_fetch_row”,但我无法通过调整来写入它

我应该怎么?

4

1 回答 1

0

您使用 mysql_fetch_row 的函数:

<?php 
function ss($s1, $s2, $s3, $s4, $s5, $s6) 
{
    $sonucArray = array("alti" => 0, "bes" => 0, "dort" => 0, "uc" => 0, "iki" => 0);
    $sayiArray = array($s1, $s2, $s3, $s4, $s5, $s6);
    $sayiArraySql = join(',',$sayiArray);  
    $query = mysql_query("select s1, s2, s3, s4, s5, s6 from loto where 
                              s1 in ($sayiArraySql) or
                              s2 in ($sayiArraySql) or
                              s3 in ($sayiArraySql) or
                              s4 in ($sayiArraySql) or
                              s5 in ($sayiArraySql) or
                              s6 in ($sayiArraySql)");

    while ($record = mysql_fetch_row($query)) 
    {
        $controlArray = array($record[0],$record[1],$record[2],$record[3],$record[4],$record[5]);
        $diffArray = array_diff($sayiArray,$controlArray);

        if (count($diffArray) == 0)
            $sonucArray["alti"]++;
        else if (count($diffArray) == 1)
            $sonucArray["bes"]++;
        else if (count($diffArray) == 2)
            $sonucArray["dort"]++;
        else if (count($diffArray) == 3)
            $sonucArray["uc"]++;
        else if (count($diffArray) == 4)
            $sonucArray["iki"]++;      
    }
    return $sonucArray;
}

mysql_fetch_row 只是使用整数而不是字段名称作为返回数组中的索引。根据您的 sql 请求,$record[0] 将是该行中的第一个字段。这就是为什么我在请求中写下每个字段名称而不仅仅是 *,以确保顺序对应。

希望有帮助。

于 2016-01-05T11:03:03.810 回答