Check for duplicates

Discuss MySQL Ajax Table Editor

Re: Check for duplicates

Postby alphalamont » Mon Mar 22, 2010 4:55 am

Here, follows the SQL for table creation:

Code: Select all
CREATE TABLE `marcas` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `marca` varchar(50) collate latin1_general_ci NOT NULL,
  PRIMARY KEY  (`id`),
  UNIQUE KEY `marca` (`marca`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=1 ;


To no repeat myself, the front-end PHP code is already posted.
Again, thanks admin.
alphalamont
 
Posts: 20
Joined: Fri Mar 12, 2010 5:55 pm

Re: Check for duplicates

Postby alphalamont » Mon Apr 12, 2010 3:36 pm

Hi admin,
At last! (it was my error)
The code you gave was 100% right - I just put it in the wrong place :oops:

For the record, and if it could help anyone else, the code
Code: Select all
function validateFun($col,$val,$row)
   {
      //$query = "select * from marcas where marca = '$val'";
      $query = "select id from marcas where marca = '$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;
      }
   }

MUST go before function initiateEditor()

Now,it works perfectly.
Thanx admin. :)
alphalamont
 
Posts: 20
Joined: Fri Mar 12, 2010 5:55 pm

Re: Check for duplicates

Postby silpher » Tue May 08, 2012 11:22 pm

Works so GOOOD!

I loved mysql ajax table editor!!! :D
silpher
 
Posts: 4
Joined: Tue May 08, 2012 6:47 pm

Re: Check for duplicates

Postby zodiac1978 » Fri Jul 06, 2012 12:10 pm

Works great! But I have one problem with the solution ...

I have a unique movie-id (as a column) and If I add a new movie it is a great way to prevent duplicates, but If I try to edit an entry it will show me the error, too! I need a "Ignore" possibility.

Best regards
Torsten
zodiac1978
 
Posts: 9
Joined: Wed Mar 07, 2012 2:38 pm

Re: Check for duplicates

Postby zodiac1978 » Fri Jul 06, 2012 4:33 pm

Is there a possibility to change "alert" to "confirm" and catch the result from this javascrript-action?
zodiac1978
 
Posts: 9
Joined: Wed Mar 07, 2012 2:38 pm

Re: Check for duplicates

Postby admin » Fri Jul 06, 2012 7:13 pm

This should be possible. You can call any custom javascript function like this
Code: Select all
$this->Editor->retArr[] = array('where' => 'javascript', 'value' => 'customJsFunction();');
admin
Site Admin
 
Posts: 1502
Joined: Fri Jul 11, 2008 1:34 am

Re: Check for duplicates

Postby zodiac1978 » Fri Jul 20, 2012 8:46 am

Thank you very much for the reply, i will try this!
zodiac1978
 
Posts: 9
Joined: Wed Mar 07, 2012 2:38 pm

Re: Check for duplicates

Postby zodiac1978 » Fri Jul 20, 2012 12:28 pm

But how to grab the result from the Javascript?

This code does not work ... :(

Code: Select all
$this->Editor->retArr[] = array('where' => 'javascript', 'value' => 'confirm("WARNING! This archivenumber already exists in database!");');
if ($this->Editor->retArr['value'] == true) { return true;  }
else { return false; }


Thanks for any hint ...
zodiac1978
 
Posts: 9
Joined: Wed Mar 07, 2012 2:38 pm

Re: Check for duplicates

Postby msavi » Thu Nov 20, 2014 7:13 am

did u ever solve this problem?
msavi
 
Posts: 62
Joined: Tue Oct 12, 2010 10:56 am

Re: Check for duplicates

Postby buconet » Fri Jul 24, 2015 7:07 pm

This works great when the criterion is for a single field , the question is how can I make the SQL conditional two fields ? namely ..

$ query = "select id where id = from brands '$ val' and NewC = '$ NewC ' " ;

and managed to obtain the second field ??

I appreciate your prompt response and assistance
buconet
 
Posts: 28
Joined: Thu May 15, 2014 8:32 pm

Previous

Return to Open Discussion

Who is online

Users browsing this forum: No registered users and 13 guests

cron