This topic is locked

disable button based on number of records found on list page

10/15/2016 1:34:19 PM
PHPRunner General questions
B
bioman author

Hi,

I am trying to limit the number of records a user can add to a specific details table based on how many records are already present. I'd like to do this by disabling the "Add New" and "Inline Add" buttons on the list page. So, for example, if a user has already added 50 records to this details table, then these buttons will no longer work and a message will be displayed.

For context,this is for a quiz app where I'd like to limit the number of questions a teacher can add.

I am having a hard time finding and using the variable that stores the info for how many records have been found for the list page. Thanks,

Brett

romaldus 10/15/2016



Hi,

I am trying to limit the number of records a user can add to a specific details table based on how many records are already present. I'd like to do this by disabling the "Add New" and "Inline Add" buttons on the list page. So, for example, if a user has already added 50 records to this details table, then these buttons will no longer work and a message will be displayed.

For context,this is for a quiz app where I'd like to limit the number of questions a teacher can add.

I am having a hard time finding and using the variable that stores the info for how many records have been found for the list page. Thanks,

Brett


https://xlinesoft.com/phprunner/docs/limit_number_of_records_users_can_add.htm

B
bioman author 10/16/2016

Hi Romaldus,

Thanks for the link. I did see this entry before but I noticed it applied to add pages. I wasn't sure if it could be applied to the list page so that the button to Add wouldn't be shown at all. Do you know if there is a way to do this (i.e. prevent the add button from appearing if the limit has been reached? I tried several things but haven't had success yet. Thanks,

Brett



https://xlinesoft.com/phprunner/docs/limit_number_of_records_users_can_add.htm

S
stiven 10/27/2016

on the list page before display event you can add this code.. you just have to create your own condition


$xt->assign('inlineadd_link',false);

$xt->assign('add_link',false);
B
bioman author 10/27/2016

Thanks for this idea. Do you know how to access the variable for the number of records found? I will need to use this in my condition, but I'm not sure how to access it. Thanks,

Brett

S
stiven 10/27/2016

just how the link says


$rs = CustomQuery("select count(*) as c from ads where userid = " . $_SESSION["UserID"]);

$data = db_fetch_array($rs);

$count = $data["c"];
if($count > 50){

$xt->assign('inlineadd_link',false);

$xt->assign('add_link',false);

}
B
bioman author 10/27/2016

Great! Thanks Stivens. I will try this out.

B
bioman author 10/28/2016

Hi,

I keep trying to use this code but I get a PHP error and the message to check my syntax near where the User Id is.

So, the error is thrown on this line:

$rs = CustomQuery("select count(*) as c from ads where userid = " . $_SESSION["UserID"]);
I'm not sure what is going wrong. It doesn't like my . $_SESSION["UserID"]) apparently, but I'm not sure what needs to be changed. Any help is appreciated. Thanks,

Brett

admin 10/28/2016

If your UserID is a text field you need to use this:

$rs = CustomQuery("select count(*) as c from ads where userid = '" . $_SESSION["UserID"]."'");
B
bioman author 10/29/2016

Thanks Sergey,

This solved the problem. Have a great night,

Brett



If your UserID is a text field you need to use this:

$rs = CustomQuery("select count(*) as c from ads where userid = '" . $_SESSION["UserID"]."'");