Php problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
cpiccini
Forum Newbie
Posts: 6
Joined: Mon Aug 21, 2006 7:17 am

Php problem

Post 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]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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)
cpiccini
Forum Newbie
Posts: 6
Joined: Mon Aug 21, 2006 7:17 am

Php problem

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Sorry, I don't understand what you're asking.
cpiccini
Forum Newbie
Posts: 6
Joined: Mon Aug 21, 2006 7:17 am

Php problem

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

count() tells you how many are in $group.
cpiccini
Forum Newbie
Posts: 6
Joined: Mon Aug 21, 2006 7:17 am

Php problem

Post 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])
???
???
Last edited by cpiccini on Tue Aug 22, 2006 9:08 am, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

cpiccini
Forum Newbie
Posts: 6
Joined: Mon Aug 21, 2006 7:17 am

Php problem

Post 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?
cpiccini
Forum Newbie
Posts: 6
Joined: Mon Aug 21, 2006 7:17 am

Php problem

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Re: Php problem

Post 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.
Post Reply