Searchin DB table

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
User avatar
phpcoder
Forum Contributor
Posts: 158
Joined: Sat Nov 02, 2002 1:18 pm
Location: Manchester, UK

Searchin DB table

Post by phpcoder »

Hi,
I got database table that contains product code, and also I got an array of product code before doing any thing I want to check either that product code exists in database table or not. How can I do thins ?
Thanks
devendra-m
Forum Contributor
Posts: 111
Joined: Wed Sep 12, 2007 3:16 am

Post by devendra-m »

thats quite simple

lets say u have array of product codes $prd_arr
get the array of product codes from database suppose $prd_db

now further codes

Code: Select all

function checkExists($prd_arr,$prd_db)
{
          foreach($prd_arr as $key=>$value)
          {
                  if(!in_array($value,$prd_db))
                         return false;
           }
           return true;
}
Post Reply