Standardized MySQL Select function

I altered a function found on php.net (http://www.php.net/manual/en/function.mysql-query.php#62227) to create a generic select function.  The query appears to work (no errors), but I can’t get the results to return.  The  call to mysql_fetch_array produces the error “supplied argument is not a valid…”.

Am I going down a dead end?


   function standardSQLSelect($strTableName, $arrValue, $arrConditionPairs){
       $strSeparator = '';
       $strValues = '';
       foreach ($arrValue as $strValue) {
           $strSetStatements = $strSetStatements.$strSeparator.$strValue;
           $strSeparator = ',';
       }
       $strSeparator = '';
       foreach ($arrConditionPairs as $strCol => $strValue){
           $strSelectConditions = $strSelectConditions.$strSeparator.$strCol.'='.quote_smart($strValue);
           $strSeparator = ' AND ';
       }
       $strSelectConditions = $strSelectConditions;
        $sql="SELECT $strSetStatements FROM $strTableName  WHERE $strSelectConditions";
        $result = mysql_query($sql);
        if(!$result) {
        die("Query Failed.".$sql.'<p>'.mysql_error());
        }
        else {
        return $result;
      }
   }
   
 echo ('<table  border="1" cellspacing="2" cellpadding="0">');
   
//example
$arrValue = array('Col1','Col2', 'Col3');
$arrConditionPairs = array('Col2' => '90','Col3' => 'foobar');

standardSQLSelect('TableName',$arrValue,$arrConditionPairs);
 
 // fetch associative array
 while($row = mysql_fetch_array($result) ) {
         $Col1 = $row['Col1'];
       $Col2 = $row['Col2'];
       $Col3 = $row['Col3'];
 
       
echo ('      <tr>
                  <td>Column 1</td>
                  <td>Column 2</td>
                  <td>Column 3</td>
            </tr>
            <tr>
                  <td>'.$Col1.'</td>
                  <td>'.$Col2.'</td>
                  <td>'.$Col3.'</td>
                  
            </tr>')      ;
      }
echo('</table>');
      
MarkMcGhieAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

akshah123Commented:
try this ...

//example
$arrValue = array('Col1','Col2', 'Col3');
$arrConditionPairs = array('Col2' => '90','Col3' => 'foobar');

$result = standardSQLSelect('TableName',$arrValue,$arrConditionPairs);  // notice the variable activated here ....
 
 // fetch associative array
 while($row = mysql_fetch_array($result) ) {
        $Col1 = $row['Col1'];
      $Col2 = $row['Col2'];
      $Col3 = $row['Col3'];
 
     
echo ('     <tr>
               <td>Column 1</td>
               <td>Column 2</td>
               <td>Column 3</td>
          </tr>
          <tr>
               <td>'.$Col1.'</td>
               <td>'.$Col2.'</td>
               <td>'.$Col3.'</td>
               
          </tr>')     ;
     }
echo('</table>');
     

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MarkMcGhieAuthor Commented:
Excellent – It worked beautifully!

Thanks
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.