title: I can't get result from mysqli query with PHP (converted from mysql_result)
body: <p>I have a PHP function that I am converting from using the mysql extension to the mysqli extension.</p>
  
  <p>Everything is going okay, until here.  I previously used a mysql_result to get a single piece of data.  There is no direct equivalent in mysqli, so I have tried the following but it still doesn't work.</p>
  
  <pre><code>function getdbvalue($table,$value,$idfield,$id) {
    $qrytext = "SELECT $value FROM $table WHERE $idfield LIKE '$id'";
    $valueqry = mysqli_query($dbh,$qrytext);
    if (FALSE === $valueqry) die("Select failed: ".mysqli_error);
    $result = mysqli_fetch_row($valueqry);
    $returnvalue = $result[0];
    return $returnvalue;
  }
  </code></pre>
  
  <p>I have verified that the variables are passing to the function okay, and the function is actually getting triggered.  If I return $id I see the ID numbers.</p>
  
  <p>I don't get an error for the query.</p>
  
  <p>SOLVED:</p>
  
  <p>I needed to add the database connection variable as a global in the function:</p>
  
  <p>Working code:</p>
  
  <pre><code>function getdbvalue($table,$value,$idfield,$id) {
    global $dbh; // This was missing!
    $qrytext = "SELECT $value FROM $table WHERE $idfield LIKE '$id'";
    $valueqry = mysqli_query($dbh,$qrytext);
    if (FALSE === $valueqry) die("Select failed: ".mysqli_error);
    $result = mysqli_fetch_row($valueqry);
    $returnvalue = $result[0];
    return $returnvalue;
  }
  </code></pre>
  
  <p>Thanks to everyone for their help. :)</p>