Page 1 of 1

Duplicate Checking/Comparing

Posted: Tue Oct 14, 2008 3:58 pm
by wescrock
Hello All,

So, I guess I am one of those needy posters... who doesn't know anything about PHP... but uses it anyways :D

my question this time...

I have a few different fields (author, keyword and potentially publisher) that have data tables as well as link tables. What I need to do is take a parameter that has been entered by the user, and compare it to the existing entries in the data table... then, if that entry already exists, use the existing keyword/author/publisher id rather than creating a new entry.

I know that it will take a foreach loop as well as an incremental counter of sorts, but im not sure as to syntax... has anyone done this before or know where I can find an example?

thanks,
Wes

Re: Duplicate Checking/Comparing

Posted: Tue Oct 14, 2008 5:17 pm
by aceconcepts
What and how might the paramters be passes? Via the url or via a form?

Re: Duplicate Checking/Comparing

Posted: Tue Oct 14, 2008 7:45 pm
by yacahuma
I very simple example

Code: Select all

 
<?
$db = //conection creatred with phpadodb
function findAuthorByName($author)
{
  $sql = "select author_id from mytable where author like '%{$author}%'";
  return $db->GetOne($sql);
}
 
if (isset($_POST['submit_btn']))
{
  $author_id = findAuthorByName($_POST['author']);
  //Now I have an id go somewhere else  
}
?>
<form action="this.php" method="post">
<input type="text" name="author" />
<input type="submit" name="submit_btn"/>
</form>
 
 
find author could return an array since there could be more than one match.

Re: Duplicate Checking/Comparing

Posted: Wed Oct 15, 2008 9:06 am
by wescrock
aceconcepts wrote:What and how might the paramters be passes? Via the url or via a form?
It would be via a form.

Re: Duplicate Checking/Comparing

Posted: Wed Oct 15, 2008 9:12 am
by aceconcepts
What about yacahuma suggestion?

Looks pretty good to me.

Re: Duplicate Checking/Comparing

Posted: Wed Oct 15, 2008 10:35 am
by wescrock
sweet deal. thanks.

I will try to use his... it looks like it will do exactly what I need it to do for most the fields that i will be checking.