Membership: List CURRENT USER items only

25 posts by 6 authors in: Forums > CMS Builder: Plugins & Add-ons
Last Post: August 4, 2011   (RSS)

By Toledoh - March 4, 2010

Hi Guys,

This should be straight forward, but I can't seem to get it.

I've got a "multi-record" section called "Client Area". Within this, I've got a field "account" with is a pick list from the user accounts table.

On the list page, I want to show only records that relate to the current user.

So at the top of the page, I need to have something like;

list($l_client_areaRecords, $l_client_areaMetaData) = getRecords(array(
'tableName' => 'l_client_area',
'where' =>'account = $CURRENT_USER['num']

));


but that doesn't work.... can you help?
Cheers,

Tim (toledoh.com.au)

Re: [Toledoh] Membership: List CURRENT USER items only

By Dave - March 8, 2010

Hi Tim,

For the where, make sure your 'account' field stores the users account number and not their name. I usually name the fields accountNum just so it's super clear what's stored in there.

Then try:
list($l_client_areaRecords, $l_client_areaMetaData) = getRecords(array(
'tableName' => 'l_client_area',
'where' => mysql_escapef(" account = ? ", $CURRENT_USER['num'] ),
));


You don't really need to escape the current user num as it's basically guaranteed to be a num. It's just a good practice though. That line is the same as the following, but uses our function:

'where' => " account = '" .mysql_real_escape_string($CURRENT_USER['num']). "'".

Hope that helps!
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Membership: List CURRENT USER items only

By Toledoh - March 8, 2010

Not working yet Dave... maybe I'm doing something wrong?

I've got a demo login: username/password client1/client1

I've got 2 pages:
http://www.forrest.id.au/test/clientList.php
http://www.forrest.id.au/test/clientList_A.php

The only difference between the 2 is;
'where' => mysql_escapef(" client_list = ? ", $CURRENT_USER['num'] ),

and "A" has;
'where' => mysql_escapef(" client_list != ? ", $CURRENT_USER['num'] ),


You can see that the second record has the client_name as "4" and the current user as "4", so shouldn't the first version of the page show that result?
Cheers,

Tim (toledoh.com.au)

Re: [Toledoh] Membership: List CURRENT USER items only

By Chris - March 9, 2010

Hi Tim,

Can you please post the complete PHP source code for clientList.php? Also, how exactly is your "client_list" field configured? Is it a Multi-Value list field, perchance?
All the best,
Chris

Re: [chris] Membership: List CURRENT USER items only

By Toledoh - March 9, 2010 - edited: March 9, 2010

Hi Chris.


client_list is a pick list from the user table. So basically, as soon as I have someone sign-up, they are added to the list for a potential "client area".

Attached is the file.
Cheers,

Tim (toledoh.com.au)
Attachments:

clientlist.php 4K

Re: [Toledoh] Membership: List CURRENT USER items only

By Chris - March 9, 2010 - edited: March 9, 2010

Hi Tim,

Please try changing this:

'where' => mysql_escapef(" client_list = ? ", $CURRENT_USER['num'] ),

to this:

'where' => mysql_escapef(" client_list LIKE ? ", "%\t".$CURRENT_USER['num']."\t%" ),

Does that solve the problem? Please let me know.
All the best,
Chris

Re: [chris] Membership: List CURRENT USER items only

By Toledoh - March 9, 2010

Sorry Chris,

I'm now getting an error:
MySQL Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1' %' ) ORDER BY client_list' at line 3

Cheers,

Tim (toledoh.com.au)

Re: [Toledoh] Membership: List CURRENT USER items only

By Chris - March 9, 2010

Hi Tim,

Sorry about that. Please try this instead:

'where' => mysql_escapef(" client_list LIKE ? ", "%\t".$CURRENT_USER['num']."\t%" ),

(I've edited my above post to be correct also.)
All the best,
Chris

Re: [chris] Membership: List CURRENT USER items only

By Toledoh - March 9, 2010

Excellent! Thanks heaps.
Cheers,

Tim (toledoh.com.au)