Page 1 of 1

Searchin DB table

Posted: Wed Jan 09, 2008 3:04 am
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

Posted: Wed Jan 09, 2008 3:18 am
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;
}