title: How to return value in php
body: <p>I am trying to return the value, i.e result of query.for the function below i am passing the product_id to get the product_name. so basically what i need to do is when i call this function i should be able to get the product_name as a return type which can be used somewhere else.</p>
  
  <pre><code>function getProductName($product_id){
      $conn = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
      if ($conn-&gt;connect_error) {
          die("Connection failed: " . $conn-&gt;connect_error);
      } 
      $sql = "SELECT product_name FROM product_list where product_id ='$product_id'";
      $result = $conn-&gt;query($sql);
      if ($result-&gt;num_rows &gt; 0) {
          while($row = $result-&gt;fetch_assoc()) {
              echo '&lt;span&gt;'. $row["product_name"].'&lt;/span&gt;';
          }
      } else {
          echo "No results found";
      }
      $conn-&gt;close(); 
      return $productName;    
  }
  </code></pre>
  
  <p>for example:</p>
  
  <pre><code>$product_name = return getProductName(45);
  </code></pre>
  
  <p>i will get <code>numark mixtrack pro 2</code> that should be able to assigned to <code>$product_name;</code> </p>
  
  <p>how can i do this?</p>