I'm trying to close and open a new tag between results, using the tags as separator in implode.
Here's the code:
$return = array();
if ($result && is_array($result) && sizeof($result)) {
foreach ($result as $row) {
$return[$row['id_feature']]['values'][] = $row['value'];
$return[$row['id_feature']]['name'] = $row['name'];
}
$tag = '</a><a>';
foreach ($return as $key=>$row) $return[$key]['value'] = implode($tag, $row['values']);
}
And here's my result:
<td><a>Moderna</a><a>Classica</a></td>
It looks great (on the code), the problem is the real result on the browser.
It appears like this (tried with Chrome, Safari and Firefox):
Moderna</a><a>Classica
I wanted to post a screenshot but I can't cause I'm a noob on stackoverflow...
I tried everything, but I haven't found a reason yet.
What's wrong? Is the function or am I wrong on thinking that I can use html as separator on implode?
I'll post the complete code, as you request:
public function getFrontFeatures($id_product, $separator = null, $id_feature = null) {
if (version_compare(_PS_VERSION_, '1.5.0.0', '>=')) {
$id_lang = (int)Context::getContext()->cookie->id_lang;
} else {
global $cookie;
$id_lang = $cookie->id_lang;
}
if ($separator == null) {
$config = $this->_getModuleConfiguration();
$separator = $config['featureSeparator'];
}
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
SELECT fp.id_feature, vl.value, fl.name
FROM `'._DB_PREFIX_.'feature_product` fp
LEFT JOIN `'._DB_PREFIX_.'feature_value` v ON (fp.`id_feature_value` = v.`id_feature_value`)
LEFT JOIN `'._DB_PREFIX_.'feature_value_lang` vl ON (v.`id_feature_value` = vl.`id_feature_value` AND vl.`id_lang` = '.(int)$id_lang.')
LEFT JOIN `'._DB_PREFIX_.'feature` f ON (f.`id_feature` = v.`id_feature`)
'.(version_compare(_PS_VERSION_, '1.5.0.0', '>=') && Shop::isFeatureActive() && Shop::getContext() == Shop::CONTEXT_SHOP ? Shop::addSqlAssociation('feature', 'f') : '').'
LEFT JOIN `'._DB_PREFIX_.'feature_lang` fl ON (fl.`id_feature` = f.`id_feature` AND fl.`id_lang` = '.(int)$id_lang.')
WHERE fp.`id_product` = '.(int)$id_product
. ($id_feature != null && $id_feature ? ' AND f.`id_feature` = '.(int)$id_feature : '')
. ' ORDER BY '
. (version_compare(_PS_VERSION_, '1.5.0.0', '>=') ? 'f.`position` ASC, ' : '')
. 'fp.`position` ASC');
$return = array();
if ($result && is_array($result) && sizeof($result)) {
foreach ($result as $row) {
$return[$row['id_feature']]['values'][] = $row['value'];
$return[$row['id_feature']]['name'] = $row['name'];
}
$tag = '</a><a>';
foreach ($return as $key=>$row) $return[$key]['value'] = implode($tag, $row['values']);
}
if ($id_feature != null && $id_feature && isset($return[$id_feature])) {
return $return[$id_feature]['value'];
} else {
return $return;
}
}
This is the code on the .tpl:
{if isset($features) && $features}
<!-- Data sheet -->
<section class="page-product-box visible-xs">
<h3 class="page-product-heading">{l s='Data sheet'}</h3>
<table class="table-data-sheet">
{foreach from=$features item=feature}
<tr class="{cycle values="odd,even"}">
{if isset($feature.value)}
<td>{$feature.name|escape:'html':'UTF-8'}</td>
<td><a>{$feature.value|escape:'html':'UTF-8'}</a></td>
{/if}
</tr>
{/foreach}
</table>
</section>
<!--end Data sheet -->
{/if}
And...now I'm not a noob anymore :D I can post screenshots:
Result:

On Inspector:

Hope this helps...
sizeof($result)is redundant after already checking$result, as an empty array will evaluate as false.<td><a>and</a></td>tags around the imploded array. Maybe you should edit to include this as it may be part of your problem.$return[$key]['value']and check with the number of characters on screen. There could be characters that don't display.<a>tags withouthrefornameto begin with?