Duplicate Checking/Comparing

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
wescrock
Forum Commoner
Posts: 31
Joined: Wed Sep 10, 2008 10:31 am
Location: Fresno, CA

Duplicate Checking/Comparing

Post 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
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: Duplicate Checking/Comparing

Post by aceconcepts »

What and how might the paramters be passes? Via the url or via a form?
User avatar
yacahuma
Forum Regular
Posts: 870
Joined: Sun Jul 01, 2007 7:11 am

Re: Duplicate Checking/Comparing

Post 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.
wescrock
Forum Commoner
Posts: 31
Joined: Wed Sep 10, 2008 10:31 am
Location: Fresno, CA

Re: Duplicate Checking/Comparing

Post 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.
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: Duplicate Checking/Comparing

Post by aceconcepts »

What about yacahuma suggestion?

Looks pretty good to me.
wescrock
Forum Commoner
Posts: 31
Joined: Wed Sep 10, 2008 10:31 am
Location: Fresno, CA

Re: Duplicate Checking/Comparing

Post 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.
Post Reply