Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/80.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
如何使用PHPjQuery加速数千个php循环_Php_Jquery - Fatal编程技术网

如何使用PHPjQuery加速数千个php循环

如何使用PHPjQuery加速数千个php循环,php,jquery,Php,Jquery,最近我开发了一个用于处理学生成绩的应用程序。算法如下: 算法: get list of all students from mysql if found get list of subject from mysql get sum of marks from mysql for each student and subject calculate pass,fail,grade point etc. insert total marks i

最近我开发了一个用于处理学生成绩的应用程序。算法如下:

算法:

get list of all students from mysql

  if found

    get list of subject from mysql

      get sum of marks from mysql for each student and subject

      calculate pass,fail,grade point etc.
      insert total marks into another table

    //end subject list

  error msg if no student

// end
这需要很长时间

现在我喜欢使用jQuery来加快速度

比如说,


将所有学生id和科目id加载到jQuery数组中。然后向PHP发送一个请求,以使用jQuery循环或任何其他方式处理结果。

很难说您真正的问题是什么,但听起来您应该做的第一件事就是避免这些循环。也许您可以使用一些存储过程将此逻辑的一部分移动到数据库中


加载数据库快照可能会显著影响性能

你说的话没有多大意义。然而,从上面的算法描述来看,似乎您正在选择学生、科目、循环中的分数,并针对每个学生的科目分数点击数据库。相反,使用表联接(
左联接
内部联接
,等等)


使用此查询,您将用数据库计算查询中的一个查询替换1000个查询。MySql将以更优化的方式运行查询,所需资源更少。

请在您认为需要时间的地方分享您的php代码。
SELECT s.*, sb.*, SUM(m.value)
FROM students AS s
  LEFT JOIN subjects as sb ON s.id = sb.student_id
  INNER JOIN marks AS m ON sb.id = m.subject_id
GROUP BY s.id, sb.id