PDA

View Full Version : comma seperated values only display first value


Vaupell
02-23-2009, 08:10 PM
Trying to achive :

1) Admin can set usergroups who can acces/use this app, in his cp
2) its stored in a table>colum , ELoptions > Optionallowed

I get the data in php like this


$getpermission=$db->query("SELECT Optionallowed FROM " . TABLE_PREFIX."ELoptions");
$permission=$db->fetch_array($getpermission);
$permissionPOSTER = htmlspecialchars_uni($permission['Optionallowed']);


And i use it in my template like this


<if condition="is_member_of($bbuserinfo, $permissionPOSTER[Optionallowed])">
<a href="Elinks.php?do=input" class="botton">$vbphrase[Btn_new]</a></div>
</if>

and for some reasion this specik one dont work, im pulling 3 other settings the same way
and they work fine, but they also are just 1 = enable 0 = disabled.

This is stored as TEXT in the db due to the "comma's" between the numbers

Since it dint work and only showed the wery first number admin sets in cp
i tryed to display the contents in a table to see what was going on.
and true it only shows the first number all others are ignored

ewen if i try to write a sentence or do anything else only the first character
is enabled..

What am i doing wrong, is it the htmlspecialchars_uni ? i dont get it
should i pull the data with an array instead, ewen with the table only
containing 1 row. :confused:

TigerC10
02-23-2009, 08:28 PM
You're close, try this:


$getpermission=$db->query("SELECT Optionallowed FROM " . TABLE_PREFIX."ELoptions");
$permission=$db->fetch_array($getpermission);
$permissionPOSTER = htmlspecialchars_uni($permission['Optionallowed']);

$permissionGROUPS = preg_split('/[\s,]+/', $permissionPOSTER );


Then just use $permissionGROUPS in your is_member_of function call.

Vaupell
02-23-2009, 08:32 PM
ohhh preg_split never knew...

Thank you!

Dismounted
02-24-2009, 04:24 AM
Unless I'm understanding something wrong, can't you just use explode() instead?

TigerC10
02-24-2009, 05:01 AM
You could, but explode has a very specific delimiter - with the preg_split he can match comma separated values, as well as comma and space separated values.