好的。我最後爲我的php文件寫了我的查詢(這會將查詢寫入一個txt文件)。但是,當我之前測試文件時,我顯然正在優化最大執行時間。我只用一個大型查詢來完成這項工作,但現在我想知道是否最好使用多個較小的查詢。 這會減少執行時間嗎?PHP:查詢超過最大時間(如何處理)
如果是這樣,那麼我對你們所有人都有另一個問題,我會怎麼做呢?這是我的文件的大部分內容:
// Query the database for data
$query = "SELECT
cards.card_id,
concat(cards.title, ' By Amy') AS cardTitle,
cards.meta_description,
cards.description,
'' as Weight,
'' as UPC,
cards.seo_keywords,
concat('http://www.amyadele.com/attachments//cards/',cards.card_id,'/',cards.card_image) AS ImageURL,
card_import.artist,
concat('ARTIST - ', card_import.artist) AS Brand,
min(card_lookup_values.card_price) AS LowPrice,
replace(lower(concat('http://www.amyadele.com/', pcat.seoname,'/',cat.seoname, '/', cards.seoname, '.htm')),' ','+') AS link,
concat(pcat.name,'>',cat.name) as Merchant,
round(min(card_lookup_values.card_price), 2) AS newPrice,
min(cast(lookup_details.value as signed)) as quantity
FROM
cards
INNER JOIN card_cheapest on cards.card_id = card_cheapest.card_id
LEFT JOIN card_import on card_import.card_id = cards.card_id
INNER JOIN card_lookup_values on card_lookup_values.card_id = cards.card_id
INNER JOIN card_categories cc ON cards.card_id = cc.card_id AND cards.card_live = 'y' AND cards.active = 'y' AND cc.active = 'Y'
INNER JOIN categories cat ON cat.category_id = cc.category_id AND cat.active = 'Y'
INNER JOIN categories pcat ON cat.parent_category_id = pcat.category_id
INNER JOIN card_lookup_values as card_values ON cards.card_id = card_values.card_id
INNER JOIN lookup_details ON card_lookup_values.lookup_detail_id = lookup_details.lookup_detail_id
WHERE card_lookup_values.lookup_id = 7
GROUP BY
cards.card_id
ORDER BY
cards.card_id";
$result = mysql_query($query);
// Open file for writing
$myFile = "google.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
// Loop through returned data and write (append) directly to file
fprintf($fh, "%-25s %-200 \n", "ID", "Name");
fprintf($fh, "\n");
while ($row = mysql_fetch_assoc($result)) {
fprintf($fh, "%-25s %-200s \n", $row['card_id'], $row['cardTitle']);
}
// Close out the file
fclose($fh);
echo "The file has been written sucessfully to googleproducts.txt. It will run again tomorrow at 12:00pm."
?>
正如你可以看到我在拉$ 查詢到$結果,然後使用該將其插入到$行。 我想我的實際問題(如果可能的話),我怎麼去有$查詢,$ query2和插入$ query2到相同的while語句?
我不知道如何解析你的問題。我在代碼中的任何地方都看不到對$ query2的引用。 – 2011-06-01 14:53:34
在兩個子查詢中拆分主查詢將無法解決php的最大執行時間問題。 – 2011-06-01 14:55:55