[英]How can I run query only once and not every time the page loads?
I need some help.我需要帮助。 The database is getting hammered with queries and I think this might be one of them.
数据库受到查询的影响,我认为这可能是其中之一。 How can I run this only one time so it does not keep running every time the page loads?
我怎样才能只运行一次,这样它就不会在每次加载页面时都继续运行?
$siteqry_rs = mysql_query($siteqry);
if (mysql_num_rows($siteqry_rs) > 0) {
while ($siters = mysql_fetch_array($siteqry_rs)) {
$tourId = $siters["Id"];
//****************** end old *******
$qry = "SELECT contentgroup.Id as
setid,contentgroup.Directory,contentgroup.Title,
contentgroup.extrafields_PHP,
DATE_FORMAT(contentgroup.AppearDate,'%d-%m-%Y') AS
add_date,DATE_FORMAT(contentgroup.AppearDate,'%m-%d-%Y') AS
add_date_format,contentgroup.SEOname AS setseoname,
contentgroup.PreviewXML_PHP ,contentgroup.Description,
SUBSTRING_INDEX(GROUP_CONCAT( DISTINCT
plg_contentasc.ModelName),',',3) AS ModelName,
SUBSTRING_INDEX(GROUP_CONCAT( DISTINCT
plg_contentasc.SEOname),',',3) AS modelseoname,
SUBSTRING_INDEX(GROUP_CONCAT( DISTINCT
plg_contentasc.Id),',',3) AS ModelId,
contentgroup.Id,
IF(tbl_set_top_rate.num_views IS
NULL,0,tbl_set_top_rate.num_views) AS setrating
FROM contentgroup INNER JOIN plg_contentascasc ON
contentgroup.Id=plg_contentascasc.ContentId
INNER JOIN plg_contentasc ON
plg_contentasc.Id=plg_contentascasc.ModelId
LEFT JOIN tbl_set_top_rate ON
contentgroup.Id=tbl_set_top_rate.set_id
INNER JOIN sites_contentgroup ON
sites_contentgroup.contentgroup=contentgroup.Id
WHERE contentgroup.websiteid='$websiteid' AND
sites_contentgroup.siteid='" . $tourId . "' AND (contentgroup.AppearDate
BETWEEN '2015-01-01' AND CURRENT_DATE)
GROUP BY contentgroup.Id
ORDER BY contentgroup.AppearDate DESC
limit 0,4";
$small = 0;
$count = 0;
$resRated = mysql_query($qry);
$show_li_counter = 0;
$shoimgcounter = 0;
if (mysql_num_rows($resRated) > 0) {
while ($mainArray = mysql_fetch_array($resRated)) {
$rowRated[] = $mainArray;
}
}
}
}
I want to run this only one time.我只想运行一次。
Use Session to store and validate your data like below使用 Session 来存储和验证您的数据,如下所示
if(empty($_SESSION['mydata'])){
//your query and prepare the result into $resultArray
$_SESSION['mydata'] = $resultArray;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.