I have an ItemCode field that is essentially a product SKU and needs to be unique for each product. How do I check for duplicates when a product is added or edited?
thanks!
$tableColumns['last_name'] = array('display_text' => 'Last Name', 'perms' => 'EVCTAXQSHO', 'val_fun' => array(&$this,'validateFun'));
function validateFun($col,$val,$row)
{
if(value does not exist)
{
return true;
}
else
{
$this->Editor->retArr[] = array('where' => 'javascript', 'value' => 'alert("Sorry this value already exists in the db");');
return false;
}
}
$query = "select id from table name where id = '$val'";
$result = mysql_query($query);
if(mysql_num_rows($result) == 0)
{
return true;
}
else
{
$this->Editor->retArr[] = array('where' => 'javascript', 'value' => 'alert("Sorry this value already exists in the db");');
return false;
}
function initiateEditor()
{
$tableColumns['id'] = array('display_text' => 'ID', 'perms' => 'TVQSXO');
$tableColumns['marca'] = array('display_text' => 'Marca', 'perms' => 'EVCTAXQSHO', 'val_fun' => array(&$this,'validateFun'));
function validateFun($col,$val,$row)
{
$query = "select id from marcas where id = '$val'";
$result = mysql_query($query);
if (mysql_num_rows($result) == 0)
{
return true;
}
else
{
$this->Editor->retArr[] = array('where' => 'javascript', 'value' => 'alert("Sorry this value already exists in the db");');
return false;
}
}
$tableName = 'marcas';
$primaryCol = 'id';
$errorFun = array(&$this,'logError');
$permissions = 'EAVIDQS';
$this->Editor = new AjaxTableEditor($tableName,$primaryCol,$errorFun,$permissions,$tableColumns);
$this->Editor->setConfig('tableInfo','cellpadding="1" width="1000" class="mateTable"');
$this->Editor->setConfig('orderByColumn','marca');
$this->Editor->setConfig('addRowTitle','Agregar');
$this->Editor->setConfig('editRowTitle','Editar');
}
$query = "select id from marcas where id = '$val'";
$query = "select id from marcas where marca = '$val'";
Users browsing this forum: No registered users and 8 guests