当用户选择特定考试时,我正在建立一个在线考试网站
然后从数据库中获取主题。然后对主题数进行计数,然后将其分配给变量$ no_of_sub。
每个主题都有存储在变量$ subject_cat [] []中的子类别。
$no_of_sub=7;//Here i assigned the no.of subject directly
$subject_cat= array ( array('Indian History','Indian national movement'),
array('Indian and World Geography',' Indian Geography',
'World Geography','Geography(jammu and kashmir)' ),
array('Indian Constitution','Indian Political History'),
array('Economic and Social Development',
'Sustainable Development',' Poverty',
' Inclusion', 'Demographics',
' Social Sector initiatives'),
array('Environmental Ecology',
'Bio-diversity and Climate Change','Physics ',
'Chemistry ','Biology','General Science'),
array('Defence Technology','Space Technology',
'Nuclear Technology','Biotechnology','Health',
'Other Technologies'),
array('Current events'),
array('General knowledge') );
//$subject_cat is a multi dimension array having sub categories for each subjects
for($i=0; $i<$no_of_sub; $i++)
//loop for subjects till no of subjects
{
for($j=0; $j<count($subject_cat[$i]); $j++)
//loop for each sub category within a subjects using multi dimensional array $subject_cat[subjects][sub_cat]
{
//Determine which subject to display the questions for
$query = "SELECT ques_id, q, op1, op2, op3, op4
FROM questions where cat='".$subject_cat[$i][$j]."' limit 3";
//for each subject category , it fetches data from MYSQL database Ex: where
cat="science"....
//
// other code goes here
//
我的问题在本地主机上运行我的代码时,它不获取所有类别,而仅获取一个类别
Where is the Indus Civilization city Lothal ? a) Gujarat b) Rajasthan c) Haryana d) Punjab
( ! ) SCREAM: Error suppression ignored for ( ! ) Fatal error: Maximum
execution time of 30 seconds exceeded in
C:\wamp\www\loginregister-master\testpage.php on line 68
我的问题是如何预防此问题,我想优化代码,因为
每次获取数据时都花了很长时间,因为我的表中每个类别的行数都超过了3000行。因此php执行时间会更长。
即使我将查询限制为1,查询也没有任何更改。
我只想从每个类别中选择一个问题,并在较短的时间内进行处理。
任何帮助我的人将不胜感激。
最佳答案
我找到了解决方案
for循环需要更多的执行时间,并且由于每个周期中的数据获取,服务器的数据缓存容量也会增加
因此,现在我使用
单独的功能。它现在完美运行,没有任何问题。