title: How to fetch data using function in PHP?
body: <p>I have this function in functions.php and I want to fetch data using this function</p>
  
  <pre><code>function getQuestionByNumber($number){
          $sql = "SELECT * FROM question WHERE id = '$number'";
          $result = mysqli_query($db, $sql);
          $row = mysqli_fetch_assoc($result);
          return $row;
      }
  </code></pre>
  
  <p>What I am trying to do is using this function I want to fetch question from question table on the test page
  Heres my test page code:</p>
  
  <pre><code>&lt;?php
      include('includes/conn.php');
      include('includes/functions.php');
  
      $number = $_GET['num'];
      $ques = getQuestionByNumber($number);
  ?&gt;
  
  &lt;textarea readonly&gt;&lt;?php echo $ques['question']; ?&gt;&lt;/textarea&gt;
  </code></pre>
  
  <p>But it is giving error:</p>
  
  <blockquote>
    <p>Notice: Undefined variable: db in
    C:\xampp\htdocs\onlineExam\testingques.php on line 9</p>
    
    <p>Warning: mysqli_query() expects parameter 1 to be mysqli, null given
    in C:\xampp\htdocs\onlineExam\testingques.php on line 9</p>
    
    <p>Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result,
    null given in C:\xampp\htdocs\onlineExam\testingques.php on line 10</p>
  </blockquote>
  
  <p>Can someone please help me I am a beginner and just started building applications</p>