我需要一些幫助與PHP代碼。 我有這樣的代碼在我的控制器/產品/ product.php(Opencart的1.5.6):如果在PHP無限
$rsNext = $this->model_catalog_product->getProduct($product_id+1);
$rsNext2 = $this->model_catalog_product->getProduct($product_id+2);
$rsNext3 = $this->model_catalog_product->getProduct($product_id+3);
$rsLast = $this->model_catalog_product->getProduct($product_id-1);
$rsLast2 = $this->model_catalog_product->getProduct($product_id-2);
$rsLast3 = $this->model_catalog_product->getProduct($product_id-3);
if($rsNext):
$this->data['next_url'] = $this->url->link('product/product', 'product_id=' . $rsNext['product_id']);
$this->data['next_text']= $rsNext['name']." >>";
elseif($rsNext2):
$this->data['next_url'] = $this->url->link('product/product', 'product_id=' . $rsNext2['product_id']);
$this->data['next_text']= $rsNext2['name']." >>";
elseif($rsNext3):
$this->data['next_url'] = $this->url->link('product/product', 'product_id=' . $rsNext3['product_id']);
$this->data['next_text']= $rsNext3['name']." >>";
else:
$this->data['next_url'] = '';
$this->data['next_text']= '';
endif;
if($rsLast):
$this->data['prev_url'] = $this->url->link('product/product', 'product_id=' . $rsLast['product_id']);
$this->data['prev_text']= "<< ".$rsLast['name'];
elseif($rsLast2):
$this->data['prev_url'] = $this->url->link('product/product', 'product_id=' . $rsLast2['product_id']);
$this->data['prev_text']= "<< ".$rsLast2['name'];
elseif($rsLast3):
$this->data['prev_url'] = $this->url->link('product/product', 'product_id=' . $rsLast3['product_id']);
$this->data['prev_text']= "<< ".$rsLast3['name'];
else:
$this->data['prev_url'] = '';
$this->data['prev_text']= null;
endif;
我如何才能讓這無限的,因爲在哪裏需要例如以上的product_id + 15的情況。 謝謝!
無限?這將需要無限的時間來執行代碼。你如何使用循環? – Xorifelse
這是我想要的,但我如何讓循環?如果我將循環這將影響我的負載速度? –
使用while或foreach循環 –