This topic is locked

Limit Number of Records per User?

10/11/2006 5:50:41 AM
PHPRunner General questions
T
tm2000 author

I have a Database with indvid user each with their own contact name records.. I want to limit the number of contacts that each user can have to 10. So when they have added 10, they can a message saying they have reached their limit and can delete and/or edit what they have..
Have no friggin idea how I go about doing that.. Anyone know?

J
Jane 10/11/2006

Hi,
you can do it using events.

Proceed to the Events tab, select Before record added event and add your code in it.

Here is a sample code:

function BeforeAdd(&$values)

{

global $conn;

$str = "select count(*) from TableName where FieldName='".$_SESSION["UserID"]."'";

$rs = db_query($str,$conn);

$data = db_fetch_numarray($rs);

if ($data[0]>10)

{

echo "You added 10 records. You can't add more that 10 records.";

return false;

}

else

return true;

}



where TableName is you actual table name, FieldName is your actual field name where username is stored.

T
tm2000 author 10/18/2006
T
tm2000 author 11/3/2006

Uh oh <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=12469&image=1&table=forumreplies' class='bbc_emoticon' alt=':blink:' />
I added a Join Statement and now this does not limit adds..

Inner Join `cms_users` ON `cms_details`.`refUsr` = `cms_users`.`username`

Left Outer Join `cms_register` ON `cms_users`.`id` = `cms_register`.`user_id`


Any ideas what to do?
My Events Code is this:

function BeforeAdd(&$values)

{

global $conn;

$str = "select count(*) from cms_users where refUsr='".$_SESSION["UserID"]."'";

$rs = db_query($str,$conn);

$data = db_fetch_numarray($rs);

if ($data[0]>2)

{

echo "You have added 2 records. You can't add more that 2 records with the Package.";

return false;

}

else

return true;

}

J
Jane 11/3/2006

Hi,
do you have joined fields on the ADD page?

T
tm2000 author 11/3/2006

Hey Jane.. Thanks for the quick reply.. Yeah, looks like I did have one.. I since unchecked it.. rebuilt things and still is not limiting things..
Any ideas?

T
tm2000 author 11/4/2006

Jane... Can I send you my files for you to review? Don't know what else to do.. I have played with it and no luck.. <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=12505&image=1&table=forumreplies' class='bbc_emoticon' alt=':(' />

Admin 11/6/2006

Hi,
you need to inspect the actual contents of refUsr field in cms_users table.

Looks like usernames are not stored there.

T
tm2000 author 11/9/2006

... you need to inspect the actual contents of refUsr field in cms_users table.

Looks like usernames are not stored there.


No, that's the right field.. it is the same one I am using for the login fields.. <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=12709&image=1&table=forumreplies' class='bbc_emoticon' alt=':huh:' />
One of the changes is that the new code - which does not work had a dbase table with an underscore.. Is there sometihng I have to do with that?
Was when it worked

$str = "select count(*) from testone where refUsr='".$_SESSION["UserID"]."'";





Now - and NOT working

$str = "select count(*) from cms_users where refUsr='".$_SESSION["UserID"]."'";


Is there maybe a quote" or ' something????

Admin 11/10/2006

Hi,
no, the cms_users table name is good enough and don't need to be enclosed in tickles.

T
tm2000 author 11/10/2006

Thanks for getting back to me.. So it has to be someting in my Join MySQL Query? Since it worked before I changed it..
Here is both below:

SELECT

`dds_database`.`refDoc`,

`dds_database`.`title`,

`dds_database`.`fName`,

`dds_database`.`mName`,

`dds_database`.`lName`,

`dds_database`.`degree`,

`dds_database`.`addie1`,

`dds_database`.`addie2`,

`dds_database`.`city`,

`dds_database`.`state`,

`dds_database`.`zip`,

`dds_database`.`phone`,

`dds_database`.`fax`,

`dds_database`.`email2`,

`dds_database`.`specialty`,

`dds_database`.`cliNum`,

`jos_users`.`id`,

`jos_users`.`name`,

`jos_users`.`username`,

`jos_users`.`email`,

`jos_users`.`usertype`,

`dds_extdetails`.`id`,

`dds_extdetails`.`user_id`,

`dds_extdetails`.`fullnamez`,

`dds_extdetails`.`addressz`,

`dds_extdetails`.`addresszz`,

`dds_extdetails`.`cityz`,

`dds_extdetails`.`statez`,

`dds_extdetails`.`zipcodez`,

`dds_extdetails`.`phonez`,

`dds_extdetails`.`faxz`,

`dds_extdetails`.`usernamez`,

`dds_extdetails`.`emailz`,

`dds_extdetails`.`passwordz`,

`dds_extdetails`.`bioz`

FROM

`dds_database`

Inner Join `jos_users` ON `dds_database`.`refDoc` = `jos_users`.`username`

Left Outer Join `dds_extdetails` ON `jos_users`.`id` = `dds_extdetails`.`user_id`


And then my Limits.. under the dds_database -- Table Events -- Before Record is Added

// Parameters:

// $values - Array object.

// Each field on the Add form represented as 'Field name'-'Field value' pair
function BeforeAdd(&$values)

{

global $conn;

$str = "select count(*) from dds_database where refDoc='".$_SESSION["UserID"]."'";

$rs = db_query($str,$conn);

$data = db_fetch_numarray($rs);

if ($data[0]>2)

{

echo "You have added 2 records. You can't add more that 2 records with the Package.";

return false;

}

else

return true;

}


Do you see anything that could be causing the limit NOT to occur? Don't know what else it could be.. THANKS!!

D
Dale 11/10/2006

Just a shot,
Your last outer join as below,
Left Outer Join `dds_extdetails` ON `jos_users`.`id` = `dds_extdetails`.`user_id`
What about changing the order to

Left Outer Join `dds_extdetails` ON `dds_extdetails`.`user_id` = `jos_users`.`id`
As I said, just a shot. You might want to wrap parenthesis around the On clauses, ie

Left Outer Join `dds_extdetails` ON (`dds_extdetails`.`user_id` = `jos_users`.`id`)
As I said, just a shot.

T
tm2000 author 11/10/2006

Thanks Dale.. I will give that a shot and see what happens..

T
tm2000 author 11/14/2006

DaleM.. Thanks for the note.. Either way, did not work..



Anyone else have any Ideas?
Don't really know what to do now?? THANKS!

D
Dale 11/14/2006

Sorry to waste your time, it was just a thought.

NOT being a mysql guru gets me into lots of frustrating areas, sometimes just switching things around and poof it works.

T
tm2000 author 11/14/2006

Sorry to waste your time, it was just a thought....

Hey DaleM.. No worries, I appreciate the post and thought... Your idea was better then the one I had - yeah, I did NOT have any <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=12854&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' /> Thanks..

Admin 11/14/2006

I must be missing something here.
How is number of contacts that each member allowed to have is related to that inner join query?