title: custom function to dynamically return database value in php
body: <pre><code>&lt;?php
  function  createDBQuery($tableName, $condition, $cvalue,$pos) {
  include('../connect.php');
  
  $sqlStatement="select * from  $table where $condition = $cvalue";
  
  $result = $db-&gt;prepare($sqlStatement);
  
  $result= $result-&gt;execute(); 
  
  for($i=0; $rowTable = $result-&gt;fetch(); $i++){
  
  
      if($rowTable)
      {
          echo $rowTable[$pos];
      }
      else
      {
          echo $rowTable[0];
      }
  
  
  }       
  </code></pre>
  
  <p>}</p>
  
  <p><strong>Body</strong></p>
  
  <pre><code>$cval=$row['fileID'];
  $file= createDBQuery('file','fileID',$cval,'1');
  //print_r($file); 
  echo $file; 
  </code></pre>
  
  <p><strong>Output</strong></p>
  
  <blockquote>
    <p>Call to a member function fetch() on boolean in C:\xampp\htdocs\pos\main\purchase.php:88 </p>
  </blockquote>