Q:

Issue Undefined variable after storing mysql query into a php variable

I have an issue on my php script. I am trying to store mysql query into a php variable and then I convert the result to string. It seems doing the job in the loop but at the end of my script, I have an error:
Internal Error -

Notice:Undefined variable: result

I want to pass the whole content of the variable $data.
Do you know what i am doing wrong? 
Here my php script:
<?php
if (isset($_GET['data']) && $_GET['data']) {
$SelectDataFromRunTable="Select Reference, Variant, HGVSVar FROM run29012016";
$QueryResult=mysqli_query($conn,$SelectDataFromRunTable);
while($data = mysqli_fetch_array($QueryResult,MYSQLI_BOTH)){
print_r($data);
$data=implode(" ",$data);
}//end of while
$NameChecker='astringtest';
$options = array('features' => SOAP_SINGLE_ELEMENT_ARRAYS);

    $client = new SoapClient($URL, $options);
try {
   $result = $client->submitBatchJob(array('data'=>$data, 'process'=>$NameChecker))
                  ->submitBatchJobResult;

    } catch (Exception $e) {
        echo $e->getMessage();
    }

print_r($result);

mysqli_close($conn);
}
?>

A:

while($data = mysqli_fetch_array($QueryResult,MYSQLI_BOTH)){
  $data = implode(" ",$data);
}

This can not work, as you overriding $data with every loop:
while($data = mysqli_fetch_array(...)) will evaluate as many times you have rows in your dataset, till the end. The last assignmet is $data = null (e.g. when you reached the end of you result set) and you are going out of the while-loop.
What you can do is, store you data into another variable, like
$soap_data = "";
while($data = mysqli_fetch_array($QueryResult,MYSQLI_BOTH)){
  $soap_data .= " " . implode(" ",$data);
}

//...

$result = $client->submitBatchJob(array('data'=>$soap_data, 'process'=>$NameChecker))
                  ->submitBatchJobResult;

Also, what devpro said, it is always better to include a default for variables.

