php - Prestashop make the integer explode in smarty -


i doing small module in prestashop. in have taken database (ps_customer_module) this

id image_id customer_name  1  2        john 2  23       simon 3  45       doe 4  9        rocky 

now fetching total database module

$get_users = 'select * '._db_prefix_.'customer_module; $users = db::getinstance()->executes( $get_users ); 

here when doing print_r($users). getting result this

array (     [0] => array         (             [id] => 1             [image_id] => 2             [customer_name] => john         )      [1] => array         (             [id] => 2             [image_id] => 23             [customer_name] => simon         )     [2] => array         (             [id] => 3             [image_id] => 45             [customer_name] => doe         )     [3] => array         (             [id] => 4             [image_id] => 9             [customer_name] => rocky         )                ) 

now have assigned array smart template this

$this->context->smarty->assign( 'users', $users ); 

and showing result in list foreach loop this

<ul>     {foreach from=$users item=row}     <li>         <h3>{$row.customer_name}</h3>         <img src="img/{$row.image_id}/{$row.image_id}.jpg" alt="">     </li>     {/foreach} </ul> 

above method works fine single image_id number image. lets image_id 1 working fine there. if image id 45 doing

<img src="img/45/45.jpg" alt=""> 

but actual image directory this

<img src="img/4/5/45.jpg" alt=""> 

so can kindly tell me how explode image_id when there image_id 2 digits , make separate them / (slash). hope point. appreciable. thanks

you need use php functions str_split , implode modifiers (you can of course same in php if want). i've created sample script that.

php file:

$users = array (     0 => array     (         'image_id' => 2      ),     1 => array     (         'image_id' => 45      ),     2 => array     (         'image_id' => 101      ),     3 => array     (         'image_id' => 2012      ),  );  $smarty->assign('users',$users); 

smarty template:

{foreach from=$users item=row}     img/{$row.image_id|str_split|implode:'/'}/{$row.image_id}.jpg<br /> {/foreach} 

output:

img/2/2.jpg img/4/5/45.jpg img/1/0/1/101.jpg img/2/0/1/2/2012.jpg 

ps. should provide php data in questions not using var_dump using var_export can pasted without modifications.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -