Ребят помогите оптимизировать код! Грузиться долго а товаров еще не так много! Вот сам код, может примитивные ошибки наделал - буду благодарен очень!
<?php
$start = microtime(true);
date_default_timezone_set('Europe/Kiev');
include('db_bace.php');
$connect_to_db = mysql_connect($db_host, $db_username, $db_password) or die("Could not connect: " . mysql_error());
mysql_query("SET NAMES utf8");
mysql_select_db($db_name, $connect_to_db) or die("Could not select DB: " . mysql_error());
$qrs_result = mysql_query("select * from oc_category ") or die(mysql_error());
while ($data_s = mysql_fetch_array($qrs_result)) {
$category_id = $data_s['category_id'];
$parent_id = $data_s['parent_id'];
$advx_result = mysql_query("select * from oc_category_description where (category_id = $category_id)") or die(mysql_error());
$oc_category_description = mysql_fetch_array($advx_result);
if ($parent_id == 0) {
$cat_text .= ("<category id=\"$category_id\">" . $oc_category_description['name'] . "</category>");
} else {
$cat_text .= ("<category id=\"$category_id\" parentID=\"$parent_id\">" . $oc_category_description['name'] . "</category>");
}
}
$qr_result = mysql_query("select * from oc_product ") or die(mysql_error());
while ($data = mysql_fetch_array($qr_result)) {
$product_id = $data['product_id'];
$manufacturer_id = $data['manufacturer_id'];
$ad_result = mysql_query("select * from oc_product_description where (product_id = $product_id)") or die(mysql_error());
$oc_product_description = mysql_fetch_array($ad_result);
$dad_result = mysql_query("select * from oc_product_to_category where (product_id = $product_id)") or die(mysql_error());
while ($oc_product_to_category = mysql_fetch_array($dad_result)) {
$oc_product_to_category2 = $oc_product_to_category['category_id'];
$dad_result23 = mysql_query("select * from oc_category where (category_id = $oc_product_to_category2)") or die(mysql_error());
$oc_product_description33 = mysql_fetch_array($dad_result23);
$category_id23 = $oc_product_description33['category_id'];
$parent_id23 = $oc_product_description33['parent_id'];
if ($parent_id23 == 0) {
$cat_azamat = ("$category_id23");
} else {
$cat_azamat = ("$parent_id23");
}
}
$dads_result = mysql_query("select * from oc_url_alias where (query = 'product_id=$product_id')") or die(mysql_error());
$oc_url_alias = mysql_fetch_array($dads_result);
$dsdf_result = mysql_query("select * from oc_manufacturer where (manufacturer_id = $manufacturer_id)") or die(mysql_error());
$oc_manufacturer = mysql_fetch_array($dsdf_result);
$text .= ("<item id=\"$product_id\" available=\"true\">
<name>" . $oc_product_description['name'] . "</name>
<categoryId>$cat_azamat</categoryId>
<price>" . $data['price'] . "</price>
<url>site.ru" . $oc_url_alias['keyword'] . "</url>
<picture>site.ruimage/" . $data['image'] . "</picture>
<vendor>" . $oc_manufacturer['name'] . "</vendor>
<description>
" . $oc_product_description['description'] . "
</description>
<warranty>1</warranty>
</item>");
}
$parse_date = date("Y-m-d");
$parse_time = date("H:i");
$full_text = ("<price date=\"$parse_date $parse_time\">
<name>Тайтл</name>
<currency id=\"UAH\" rate=\"1\" plus=\"0\"/>
<catalog>" . $cat_text . "</catalog>
<items>" . $text . "</items>
</price>");
echo $full_text;
$file_name = '/var/www/***/data/www/***/parser.xml';
$w = fopen($file_name, 'w');
fwrite($w, $full_text);
fclose($w);
mysql_close($connect_to_db);
$time = microtime(true) - $start;
printf('Скрипт выполнялся %.4F сек.', $time);
?>