This topic is locked

Default Value

1/31/2017 9:42:10 AM
PHPRunner General questions
C
cjsaputo author

I have read as much as I can about this but still don't understand and can't make it work.
Table = donors

Field = donorid
Table = donor_id

Field = donorid_control
When I add a new record to the donors table I want the donorid field to default to the value in donorid_control.
After the donors record is added I want to increment the value of donorid_control by one.
Any help would be appreciated.

romaldus 1/31/2017

What do you mean with:

"...

C
cjsaputo author 2/2/2017



What do you mean with:

"...


I want to get the value in donorid_control and store it in donorid.

Admin 2/3/2017

This question doesn't make much sense in the way it is asked. Tables normally have multiple records and it is not clear how do you pick a single value from that table.

romaldus 2/4/2017

[size="5"]In table
[size="2"][b][color="#0000ff"]before record added event :
[/size]



//select max value from donorid_control in table donor_id and insert it to donorid field in donors table

$sql="select max(donorid_control) as mx from donor_id order by mx";

$rs=CustomQuery($sql);

$data=db_fetch_array($rs);

$str=($data["mx"]);
$values["donorid"]=$str;


after record added event :



//add new record to donorid_control in donor_id table by increase the value by 1

$sql="select max(donorid_control) as mx from donor_id order by mx";

$rs=CustomQuery($sql);

$data=db_fetch_array($rs);

$str=($data["mx"]+1);
$sql = "INSERT INTO donor_id (donorid_control) values (".$str.")";

CustomQuery($sql);


That's it

C
cjsaputo author 2/4/2017



This question doesn't make much sense in the way it is asked. Tables normally have multiple records and it is not clear how do you pick a single value from that table.


My question probably did make an assumption so I will clarify. The control table has only one record and the id field is the next id that is to be assigned if a completely new donor is added. The same person/donor can donate more than once and will have the same donor id for each of their records in the donor table. If someone is donating for the first time their donor record will be assigned the donor id from the control table. Then the id in the control table will be incremented by one once the donor record is added.
As I see it the biggest issue is to ensure that the new donor is NOT already in the donor table.
I am not sure if this new explanation will change your sample code?? If you think this needed solution is too complex for the forum I would like to explore a final solution as this is beyond my capabilities.
Thanks, Chuck

romaldus 2/5/2017

Perhaps you can incluce some screenshots

HJB 2/5/2017

It seems as if a kind of re-invention of the wheel is somehow on here. World's best RAD tool ever has a built-in field feature named "No duplicate field entries".

So, once a NEW record is added, the auto-incremental function of ID assignment in junction with "No duplicate field entries" would automatically sort out the problem

as any NEW donator would be assigned to an auto-incremental ID anyway why existing donators can repeat donations too. Just my 2 cents on the issue ...
P.S. https://xlinesoft.com/phprunner/docs/hide_repeating_values_on_list_page.htm
... is providing best VIEW of ID's of all kinds of donators (NEW = ONE ID and ONE ROW, multiple DONATORS = ONE ID, MULTIPLE ROWS)
P.S. Correct naming inside world's best RAD tool reads: PREVENT DUPLICATE VALUES

( view 2nd screenshot inside https://xlinesoft.com/phprunner/docs/_edit_as__settings.htm )

C
cjsaputo author 2/9/2017

I have decided to simplify, I thought.
I have removed the "Add" button from the Donor List screen because the Member must exist first and this is an easier approach, and no hardship on the user.
Second, I added a link at the end of each row of the Members List screen with the following code:

$value = "<a href='donors_add.php?firstname=".$data["first_name"]."&lastname=".$data["last_name"]."&donorid1=".$data["donorid"]."&donorid2=".$data["donorid_control"]."'>Donation</a>";
I have verified that this works. I used $_GET's for each variable in the default value field on the Donor Add screen and the donorid, first_name and last_name fields are correct. I also tried a $_GET for donorid2 instead of donorid1 and the value is correct.
The next thing I tried was to use the "Add page: before process" event, I also tried this in the "Before display" event. The code I added was:

If ($data["donorid1"] < "1") {

$_GET["&donorid2"];

} else {

$_GET["&donorid1"];
I have modified this code a number of different ways but nothing works. It is a fact that the donorid field in the Member table is either 0 or blank for members who have never donated, depending on how old the Member record is.
Am I misusing the event, or is my code just bad?
Thanks, Chuck



It seems as if a kind of re-invention of the wheel is somehow on here. World's best RAD tool ever has a built-in field feature named "No duplicate field entries".

So, once a NEW record is added, the auto-incremental function of ID assignment in junction with "No duplicate field entries" would automatically sort out the problem

as any NEW donator would be assigned to an auto-incremental ID anyway why existing donators can repeat donations too. Just my 2 cents on the issue ...
P.S. https://xlinesoft.com/phprunner/docs/hide_repeating_values_on_list_page.htm
... is providing best VIEW of ID's of all kinds of donators (NEW = ONE ID and ONE ROW, multiple DONATORS = ONE ID, MULTIPLE ROWS)
P.S. Correct naming inside world's best RAD tool reads: PREVENT DUPLICATE VALUES

( view 2nd screenshot inside https://xlinesoft.com/phprunner/docs/_edit_as__settings.htm )

Admin 2/13/2017

The following line of code is meaningless:

$_GET["&donorid2"];


First of all correct syntax is $_GET["donorid2"], ampersand is used to separate parameters from each other.
Second, you need to do something with the value you are reading from the URL. You are not doing anything with this value.

C
cjsaputo author 2/14/2017



The following line of code is meaningless:

$_GET["&donorid2"];


First of all correct syntax is $_GET["donorid2"], ampersand is used to separate parameters from each other.
Second, you need to do something with the value you are reading from the URL. You are not doing anything with this value.


Other than the syntax with the "&" I think you are mistaken. Forgive me if I am wrong.
In a prior line of code, which I included in my last post, I loaded donorid2 with the value from donor_control, which is the control value from the single record table. My goal is to test the value of donorid in the member record to see if it is less that 1. If it is then I know that this member has never donated and does not already have a record in the donor table. Therefore, I want to store the donorid2 value into the donorid field. Also, if the value of donorid from the member record is greater than zero then I want to store the value from donorid from the member record, which was stored into donorid1, into the donorid field in the donor table record.
Does this help?
Thanks, Chuck