我正在尝试获取包含其各自产品的子类别列表。 如果我有50个产品和3个类别,则该代码有效。 问题是:如果我有1500多种产品,分为6类,我的代码将返回一个错误页面,显示加载所需的等待时间(我认为)。
$prodotti = '';
foreach ($children as $chi){
$prodotti .= '
<div style="">
<table style="width: 100%">
<tr>
<th align="left">
'.$chi[name].'
</th>
<th></th>
<th></th>
</tr>
<tr>
<th style="width: 80%">
Prodotto
</th>
<th align="right" style="width: 10%">
N. Valori
</th>
<th align="right" style="width: 10%">
Prezzo
</th>
</tr>';
foreach ($products as $pro){
if(in_array($chi[id_category],Product::getProductCategories($pro[id_product]))){
$prodotti .= '
<tr>
<td style="font-size: 9pt; color: #9E9F9E">
'.$pro[name].'
</td>
<td align="right" style="font-size: 9pt; color: #9E9F9E">
...
</td>
<td align="right" style="font-size: 9pt; color: #9E9F9E">
'.$my_currency_iso_code.'
'.$pro[price].'
</td>
</tr>';
}
}
$prodotti.='
</table>
</div>';
}
谢谢,问候
答案 0 :(得分:0)
@曲棍球
我不得不稍微更改一下代码。 现在,代码将创建一个数组,在其中将找到与类别关联的产品,然后将通过smarty发送该数组。
我尝试使用microtime(); ……但是,尽管我一直在寻找向导,但我不知道该操作。
返回的值如下:0.81050395965576
这是带有microtime()实现的新代码:
public function __construct($id_lista, $smarty)
{
$this->idlista = $id_lista;
$this->smarty = $smarty;
$this->id_lang = Context::getContext()->language->id;
$idlang = $this->id_lang;
$this->id_shop = Context::getContext()->shop->id;
$idshop = $this->id_shop;
/*********************************************************************/
//Get $icpn['id_category'], $icpn['lista_name'], $icpn['id_currency']
$icpn = Db::getInstance()->getRow('SELECT cate_list, lista_name, id_currency FROM '._DB_PREFIX_.'rec_ps_beta WHERE id_rec_ps_beta = "'.$id_lista.'"');
//Update di listalink e lastupdate
Db::getInstance()->execute('UPDATE '._DB_PREFIX_.'rec_ps_beta SET listalink = "'._PS_BASE_URL_._MODULE_DIR_.'recpsbeta/lista/'.$icpn['lista_name'].'.lista", lastupdate = CURRENT_TIMESTAMP WHERE id_rec_ps_beta = "'.$id_lista.'"');
//VALUTA
$context = Context::getContext();
$currency = $context->currency;
$id_pscurr = $currency->id;
if($id_pscurr == $icpn['id_currency']){
$converti = 0;
}else{
$converti = 1;
}
//segno valuta
$setcurrency = new CurrencyCore($icpn['id_currency']);
$sig_setcurr = $setcurrency->sign;
$this->cateinfo = Category::getCategoryInformations(explode(',', $icpn['cate_list']));
$timecate_start = microtime(true);
foreach($this->cateinfo as $cats){
$products = Product::getProducts ($idlang, 0, 0, 'name', 'ASC', $cats['id_category'], true);
foreach ($products as $pro){
if($converti == 0){
$price = $pro['price'];
$price = number_format($price, 2).' '.$sig_setcurr;
}
elseif($converti == 1){
$price = Tools::convertPrice($pro['price'],$id_setcurr);
$price = number_format($price, 2).' '.$sig_setcurr;
}
$products_arr[] = array ('ctid'=>$cats['id_category'],
'name'=>$pro['name'],
'price'=>$price
);
}
}
$timecate_end = microtime(true);
$this->$timecate_end_start = $timecate_end - $timecate_start;
$this->products_arr = $products_arr;
$this->listaname = $icpn['lista_name'];
}
我应该如何解释以下结果:0.81050395965576?