This topic is locked

limit user to 40 or 100 records?

8/20/2010 8:26:50 PM
PHPRunner General questions
W
wfcentral author

I have a client who wants me to build a database that will allow him to put companies in one table with a "number of members" they are allowed. Then, he will give them access to a member database and they can add that many members.
So, if I have a table like this...
COMPANIES

id, name, username, password, number of members allowed
MEMBERS

id, name, company_ID
is it possible in phpRunner to make it so they cannot add any more than the number they are allowed? If they are allowed to add 40 members once it hits that number they cannot add anymore unless they delete some.
thanks in advance,

Robert

A
ann 8/23/2010

Robert,
you can check the number of records in the Before record added event on the Events tab and prevent saving if there are more than 40 members.

Here is a sample code:

$rs=CustomQuery("select `number of members allowed` from COMPANIES where id=".$values["company_ID"]);

$data=db_fetch_array($rs);

if ($data["`number of members allowed`"]==40){

return false;

}

else{

return true;

}
W
wfcentral author 10/1/2010

maybe I'm reading your sample wrong, but it looks to me like if they have 40 members allowed in the database then this code will prevent them from saving ANY new records?
I don't see where it is checking the current number of records they have created against the number they are allowed...
I understand what I'm trying to do, but do not know how to write it for phpRunner...
here's what I'm trying

  • get number of records allowed for this customer
  • number allowed = 40
  • get number of records this company has created
  • number created = 38
  • since number created is < number allowed... let them create another record
  • if number created is = number allowed... tell them you cannot create another record, you must edit or delete one of your records


    Robert,
    you can check the number of records in the Before record added event on the Events tab and prevent saving if there are more than 40 members.

    Here is a sample code:

$rs=CustomQuery("select `number of members allowed` from COMPANIES where id=".$values["company_ID"]);

$data=db_fetch_array($rs);

if ($data["`number of members allowed`"]==40){

return false;

}

else{

return true;

}


Sergey Kornilov admin 10/2/2010

Here is the sample code you looking for. Make sure to replace all field and table names.

$rs=CustomQuery("select `number of members allowed` from COMPANIES where id=".$values["company_ID"]);

$data=db_fetch_array($rs);

$rs2=CustomQuery("select count(*) as c from TableInQuestion where UserID=".$values["company_ID"]);

$data2=db_fetch_array($rs2);
if ($data["`number of members allowed`"]>$data2["c"]){

return true;

}

else{

$message = 'You cannot add more records';

return false;

}