Page 1 of 1

Php problem

Posted: Mon Aug 21, 2006 7:29 am
by cpiccini
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hello. This is the first time i try using php language end i've a small problem.

In this module this function give me all categories that a user can access.

Code: Select all

$result = $xoopsDB->query("SELECT a.*, b.* FROM " . $xoopsDB->prefix("PDdownloads{$mydirnumber}_cat") . " a, ".$xoopsDB->prefix('group_permission')." b WHERE a.cid = b.gperm_itemid AND b.gperm_modid = $module_id AND b.gperm_name = \"PDDownCatPerm{$mydirnumber}\" AND b.gperm_groupid = $groups[0] AND a.pid = 0 ORDER BY a.weight");

Users can have more then 1 group and $groups array is list of all groups of a user.
The code i posted check only first group of a user
the sentence "AND b.gperm_groupid = $groups[0]" is probably the part i had to change but i don't now right sentence.

if you known how help me, please reply at support@softmerlino.com.

Thank you.


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Mon Aug 21, 2006 8:55 am
by feyd
You may want to look at the IN() syntax, otherwise the syntax would be

Code: Select all

..AND (`field` = 'value1' OR `field` = 'value2' OR `field` = 'value3' etc)

Php problem

Posted: Tue Aug 22, 2006 2:55 am
by cpiccini
Thanks for your replay.

This is the first solution i used but there are 2 problems

1) I can't know count of array

2) I modified sentence with

Code: Select all

AND (b.gperm_groupid = $groups[0] OR b.gperm_groupid = $groups[1])
but only user that are in both $groups[0] and $groups[1] are ok! Users that have only $group[1] are ko!

Do you know is exist command to test if b.gperm_groupid is present into all array?

Thanks

Posted: Tue Aug 22, 2006 8:27 am
by feyd
Sorry, I don't understand what you're asking.

Php problem

Posted: Tue Aug 22, 2006 8:47 am
by cpiccini
retry... Sorry but my english is very bad!!!

I change sentence
with
Code:
AND (b.gperm_groupid = $groups[0] OR b.gperm_groupid = $groups[1])


but if I'm using an user that have only 1 group setting, my script don't work right.

Also, I needed a sentence that check if b.gperm_groupid is present in $group, but i don't know how many groups exist, so i can't write a code like you say.


For example if i need to do this with another language (for example cobol) i simply write
perform until b.gperm_groupid = $groups(ind) or ind > 999
add 1 to ind
end-perform

Posted: Tue Aug 22, 2006 8:53 am
by feyd
count() tells you how many are in $group.

Php problem

Posted: Tue Aug 22, 2006 9:02 am
by cpiccini
ok so if i use

Code: Select all

$myind = count($groups)
the variabile "$myind" is the number of groups.

But how use "$myind" in

Code: Select all

AND (b.gperm_groupid = $groups[0] OR b.gperm_groupid = $groups[1])
???

Code: Select all

AND (b.gperm_groupid = $groups[1-$myind])
???

Code: Select all

AND (b.gperm_groupid = $groups[1:$myind])
???
???

Posted: Tue Aug 22, 2006 9:07 am
by feyd

Php problem

Posted: Tue Aug 22, 2006 9:23 am
by cpiccini
:oops: :? Where is the problem????

Code: Select all

$groups = (is_object($xoopsUser)) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS;

Code: Select all

$myind = count($groups);

Code: Select all

for ($i=0; $i <=$myind; $i++) $result = $xoopsDB->query("SELECT a.*, b.* FROM " . $xoopsDB->prefix("PDdownloads{$mydirnumber}_cat") . " a, ".$xoopsDB->prefix('group_permission')." b WHERE a.cid = b.gperm_itemid AND b.gperm_modid = $module_id AND b.gperm_name = \"PDDownCatPerm{$mydirnumber}\" AND b.gperm_groupid = $groups[$i] AND a.pid = 0 ORDER BY a.weight");
Probably in the position of

Code: Select all

for ($i=0; $i <=$myind; $i++)
but where i put it?

Php problem

Posted: Wed Aug 23, 2006 2:36 am
by cpiccini
:D
I solved my problem!

Thank you to feyd for your time!

Last question is, where can i find a good "step by step" debug that can show value of variables too, simple to instal and to use?

Bye

Re: Php problem

Posted: Wed Aug 23, 2006 9:10 am
by feyd
cpiccini wrote:Last question is, where can i find a good "step by step" debug that can show value of variables too, simple to instal and to use?
viewtopic.php?t=53795 may be of interest.