Duplication checking

Samuel

New member
I am looking for a way to check two fields for duplication.

I have written on this topic before, and I am hoping someone has found a solution since then..

I have two tables:

MAIN:

MAINID (primary) auto incremented
promo (int) Linked to 2nd table
code (varchar)
cems (bigint)
date (date)

PROMO:

ID (primary) auto incremented
promo (varchar)

The table linking works perfectly,

I would like the CEMS field and the DATE fields checked for duplicates..so the only the same CEMS number on the same date will be flagged..and any other CEMS numbers on the same date will be accepted.

it is part of a validation system, to prevent the same CEMS card number from being used more then once per day per offer..

I have dupe checking turned on both the CEMS & Date fields..I would like to have it check a new row of data for duplicate CEMS and Date, not the columns. It seems to check down the field columns, instead of across the table field rows.

I have also limted the field length in the Database so when the Date is inserted automatically, it inserts the date as such

2005-02-01

that is from the DadaBik, drop down choice for insert date..

any help on this would be great..

I am running dadbik 3.2 stable

Thanks
Sam

 

alpha2zee

Well-known member
Perhaps you can do this in a way other than through duplicate checking.

In the form configurator, you can set the field to be of a new content type - say cems. With other code modifications, an entered CEMS value will be tested for validity; if okay, the form data will be accepted.

If you think this sound reasonable, you can try the mod described in this post

For points 1 - 3, just substitute 'cems' for' cc_luhn,' and for 4, 'is_valid_cems' for 'is_valid_cc_luhn.' For 5, use something like this; I am not sure about the date comparison operation though (`date` = " . $_POST["date"])
[pre]
function is_valid_cems($cc)

// goal: check if value is acceptable for CEMS - for any date, no two records should have same CEMS

// output: true if it's valid, false otherwise

{

$cc = preg_replace("/\D|\s/", "", $cc); // strip any non-digits

$sql_query = "SELECT COUNT(*) FROM `MAIN` WHERE `cems` = " . $cc . " AND `date` = " . $_POST["date"];
$sql_result = mysql_query($sql_query);
$sql_count = mysql_result($sql_result, 0);
$valid = ($sql_count < 1);
return $valid;

} // end function is_valid_cems
[/pre]



Post Edited (11-29-05 18:55)
 

Samuel

New member
the same CEMS number could be valid on a different date, a patron can redeem another offer on another date, just not two offers on the same date..

I am not sure I understand all of the coding here I am fairly new at this and relying on help..I have no qualms about trying something and blowing it up..

I have good backups:)

I will read through that other post and see if I can use that as a model for what I am trying to accomplish..

Thanks,
Sam
 
Top