Need Help Limiting records to One

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
mgain2013
Posts: 27
Joined: 2013-02-16 16:12

Need Help Limiting records to One

Post by mgain2013 » 2017-09-01 05:15

Hello!!

I am working on a project where I need to limit the records to one for this table. In the past I received help when I needed to limit records when I had two linked tables. This time I have one table and I need it to only allow 1 record in the table. Any help would be greatly appreciated!

I only have two fields in this table:
Table name is:
setimage

fields are:
id
imagepath

If a person tries to add a second record it will give a message letting them know that only one record is allow for this table.

This was the previous code for two linked tables: obviously it referenced two tables. I am not strong enough in php to convert this code for one referenced table.

$b_return = true;
// only one ARC_status allowed for an ARC_request
if ($data['arcid'] != "") {
// count the linked ARC_requests
$sql_string = "SELECT ifnull(count(*),0)
FROM arcapproval
WHERE arcid = " . $data['arcid'] . ";";
$countarcrequest = sqlValue($sql_string, $o);

if ($countarcrequest != 0) {
// insert NOT allowed
// for debugging
$_SESSION['dbgStr'] = "<div><p><strong>arcapproval_before_insert; Debugging: insert NOT allowed;</strong></br>
o: " . $o . " </br>
arcid: " . $data['arcid'] . " </br>
countarcrequest: " . $countarcrequest . " </br>
</p></div>";
$b_return = false;
}
else {
// insert allowed
// for debugging
$_SESSION['dbgStr'] = "<div><p><strong>arcapproval_before_insert; Debugging: insert allowed;</strong></br>
o: " . $o . " </br>
arcid: " . $data['arcid'] . " </br>
countarcrequest: " . $countarcrequest . " </br>
</p></div>";
}
}

return $b_return;
// return TRUE;
}

Post Reply