Using the Extra Fields plugin, I am trying to display the results of a checkbox as a <li>list</li> This is my code with the results showing a Pipe Character separating the results: Code: Code: {get_extra_field id=$view fid=14} Results: Air Conditioning|Cruise|Power Locks|Power Mirrors|Power Windows| I have read the following post that touches on this subject, but it appears that lots of things have changed in the last years. After trying various things mentioned in that post, I have failed at accomplishing this. Any help would be appreciated...thanks!
I haven't tested this, but This is extracted from my custom mnt_extra_fields.php plugin that I use all the time and modified for your particular output type (e.g. you may have to "fiddle" with it a little more ): From your copy of function.get_extra_field.php file around line 66: Find this: Code: $value = $rs['sValue']; Right after that ADD the following lines: Code: // Check if this is an extra field with multiple results if (mb_substr_count($value, "|") > 0) { $value = str_replace("|", "</li><li>", $value'); // replace "|" $str_count = mb_strlen($value); // Get length $end = ($str_count - 5); // count w/o last <li> $f_string = mb_substr($value'], 0, (int)$end); // make the output list $value = "<ul><li>"; $value .= $f_string; $value .= "</ul>; } else { After the next existing line: Code: $value = $rs['sValue']; ADD another line to close the "else" statement: Code: } Like I said, I didn't test this. I just spit it out, but this should work for you. Have fun, Mike
Hi Mike...I gave it a go and was unable to see the results due to parsing errors. Any thoughts, the error showed it was coming from: Code: $f_string = mb_substr($value'], 0, (int)$end);
Yep, there's an erroneous apostrophe and right bracket. $f_string = mb_substr($value'], 0, (int)$end); Just remove those $f_string = mb_substr($value, 0, (int)$end);
Thanks very much for the help Mike, I now get the following error: Parse error: syntax error, unexpected $end in /path-to-folder/plugins/function.get_extra_field2.php on line 88 Line 88 being the end of the file The plugin code below: Code: <?php function smarty_function_get_extra_field2($params, &$smarty) { global $db,$modules; $id = isset($params['id']) ? (int) $params['id'] : 0; $fid = isset($params['fid']) ? (int) $params['fid'] : 0; $name = isset($params['name']) ? $params['name'] : FALSE; if ($id > 0) { if ($name) { $sql = 'SELECT v.sValue AS value FROM '.PREFIX.'fields n, '.PREFIX.'products_fields v WHERE v.fID = n.fID AND v.pID = '.$id.' AND n.fInternal = "'.$name.'"'; $result = $db->query($sql); if ($result->isError() OR $result->size() == 0) { $value = FALSE; } $rs = $result->fetch(); $value = $rs['value']; $result->freeResult(); } else { $sql = 'SELECT sValue FROM '.PREFIX.'products_fields WHERE pID='.$id.' AND fID='.$fid; $result = $db->query($sql); if ($result->isError() OR $result->size() == 0) { return FALSE; } $rs = $result->fetch(); $value = $rs['sValue']; // Check if this is an extra field with multiple results if (mb_substr_count($value, "|") > 0) { $value = str_replace("|", "</li><li>", $value); // replace "|" $str_count = mb_strlen($value); // Get length $end = ($str_count - 5); // count w/o last <li> $f_string = mb_substr($value, 0, (int)$end); // make the output list $value = "<ul><li>"; $value .= $f_string; $value .= "</ul>; } else { $result->freeResult(); } } return $value; } } /* End of file function.get_extra_field.php */ /* Location: ./upload/plugins/function.get_extra_field.php */ Any other thoughts?
Near the end, there is a missing quote $value .= "</ul>; Should be: $value .= "</ul>"; Sheesh, who spit out this junk code!
Man, that I should have caught myself... I made the update and then noticed that the closing bracket was missing from the last list item: <ul><li>Air Conditioning</li><li>Cruise</li><li>Power Locks</li><li>Power Mirrors</li><li>Power Steering</li><li>Power Windows</li><li>Tilt Steering</li</ul> I changed the plugin code as below: Code: $value .= "</ul>"; to Code: $value .= "></ul>"; Now all appears to be working as expected...thanks very much for your help! It might be nice to see this as a core feature of the script in the future
Glad it worked for you, but your last edit (although it works) should actually be before in this line: Code: $end = ($str_count - 5); // count w/o last <li> change it to: Code: $end = ($str_count - 4); // count w/o last <li> That would be much better syntactically (is that a word????)