-2

I am new PHP developer which revamping some old PHP source code (may be 10 years ago). Knowing that "mysql_result()" is depreated in PHP 7. May I know how to use mysqli_fetch() to replace it?

Below is part of the source code using "mysql_result()", it allows three parameters, however mysqli_fetch() just allow one parameter.

    //echo $sql;
$result = mysqli_query($conn,$sql);
$FieldData = array();

$index = 0; 
if($result) {
    while(mysqli_fetch_row($result)) {
        $num = mysqli_num_fields($result);
        for($i = 0; $i < $num; $i++) {
            $FieldName = mysqli_field_name($result, $i);
            $FieldData[$FieldName] = mysql_result($result,$index,$FieldName);
            $FieldData[$FieldName] = stripslashes($FieldData[$FieldName]);
        }
        
        break;  // Get the FIRST record if there are more than one record returned.
    }
} else {
    //echo "Error in getting a row from DB!<br />";
    $return = false;
}
Marco Bonelli
  • 55,971
  • 20
  • 106
  • 115
yrneh
  • 1
  • 3

0 Answers0