0

I received this error while trying to run the if statement for different href

Parse error: syntax error, unexpected 'if' (T_IF), expecting ')' in D:\xampp\htdocs\ramesh\wmw\catalog\controller\product\sub_category.php on line 29

sub_category.php

foreach ($category_info as $result) {
        $data['categories'][] = array(
        'name' => $result['name'],
        'parent_id' => $result['parent_id'],
        'thumb' => $this->model_tool_image->resize($result['image'], $this->config->get('config_image_category_width'), this->config->get('config_image_category_height')),
        'description' => utf8_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, $this->config->get('config_product_description_length')) . '..',
        /*'href' => $this->url->link('product/filter', '&category_id=' . $result['category_id'])
        'href' => $this->url->link('product/sub_category')*/
        if($result['category_id']==24)
        {
            'href' => $this->url->link('product/transmission', 'sub_category_id='.$result['parent_id'].'&category_id=' . $result['category_id'])
    }
    elseif
    {
            /*some code for href*/
        }

      );
}
2
  • Please check stackoverflow.com/questions/4118875/…. Commented Mar 22, 2017 at 4:40
  • thanks for replay @PhilipTzou sorry am not understand please tell me in my code. It's easy to me Commented Mar 22, 2017 at 4:47

2 Answers 2

0

Finaly i got the answer following code working fine

 foreach ($category_info as $result) {
 if($result['category_id']==24)
 {
    $link1 = $this->url->link('product/transmission', 'sub_category_id='.$result['parent_id'].'&category_id=' . $result['category_id']);
 }
else
{
    $link1 = $this->url->link($_SERVER["REQUEST_URI"]);
}
$data['categories'][] = array(
    'name' => $result['name'],
    'parent_id' => $result['parent_id'],
    'thumb' => $this->model_tool_image->resize($result['image'], $this->config->get('config_image_category_width'), $this->config->get('config_image_category_height')),
    'description' => utf8_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, $this->config->get('config_product_description_length')) . '..',
    /*'href' => $this->url->link('product/filter', '&category_id=' . $result['category_id'])
    'href' => $this->url->link('product/sub_category')
    'href' => $this->url->link('product/transmission', 'sub_category_id='.$result['parent_id'].'&category_id=' . $result['category_id'])*/
    'href' => $link1
);

}

Sign up to request clarification or add additional context in comments.

1 Comment

I got the result
0

Your code syntax is wrong. If else conditions are not allowed with in an array.

Please replace your code with the following and error will be resolved -

foreach ($category_info as $result) { $href = '';

    if ($result['category_id']==24) {
        $href = $this->url->link('product/transmission', 'sub_category_id='.$result['parent_id'].'&category_id=' . $result['category_id']);
    } else {
        /*some code for href*/
    }

    $data['categories'][] = array(
    'name' => $result['name'],
    'parent_id' => $result['parent_id'],
    'thumb' => $this->model_tool_image->resize($result['image'], $this->config->get('config_image_category_width'), $this->config->get('config_image_category_height')),
    'description' => utf8_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, $this->config->get('config_product_description_length')) . '..',
    /*'href' => $this->url->link('product/filter', '&category_id=' . $result['category_id'])
    'href' => $this->url->link('product/sub_category')*/        
    'href' => $href    

  );

}

1 Comment

Thanks for your replay @Knowband Plugins But my code working fine

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.