用逗号获取另一个php函数的值

how to get the value of an echo $burn_actual; outside php function like:

<?php $sql = "SELECT estimated_sum FROM burndown_snap WHERE project_id='$sum1 AND name='$sum2'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
    $burn_actual = "" . $row["estimated_sum"]. ",";
    echo $burn_actual;
}
}
?>

Above function works good if the echo $burn_actual; is inside the php function. Dosen't work If I put echo $burn_actual; to another php functon like that:

    <?php $sql = "SELECT estimated_sum FROM burndown_snap WHERE project_id='$sum1 AND name='$sum2'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
    $burn_actual = "" . $row["estimated_sum"]. ",";
    echo $burn_actual;
}
}
?>

<?php echo $burn_actual; ?>

Just above - I'm getting only the last value of $burn_actual from the list. How to fix that?

You need to create a function that will return an array. Later on you can use the array and output or process the values wherever you want. I would suggest you to check any programming tutorial first. Like http://www.w3schools.com/php/.

$burn_actual should be array Try this

 <?php $sql = "SELECT estimated_sum FROM burndown_snap WHERE project_id='$sum1 AND name='$sum2'";
        $result = $conn->query($sql);
        if ($result->num_rows > 0) {
        while($row = $result->fetch_assoc()) {
            $burn_actual[] = "" . $row["estimated_sum"]. ",";

        }
        }
echo '<pre>';
print_r( $burn_actual);
        ?>

Or if you want to keep it as a string

   <?php $sql = "SELECT estimated_sum FROM burndown_snap WHERE project_id='$sum1 AND name='$sum2'";
                $result = $conn->query($sql);
                if ($result->num_rows > 0) {
                while($row = $result->fetch_assoc()) {
                    $burn_actual .= "" . $row["estimated_sum"]. ",";
                    echo $burn_actual;
                }
                }
    echo  $burn_actual;
                ?>
while($row = $result->fetch_assoc()) {
    $burn_actual[] = "" . $row["estimated_sum"]. ",";
}
print_r($burn_actual);

use something like this. First assign it into an array and then accesss the array.

Your function can build the returned string by creating an array and using implode() to combine it into a comma-separated string.

function get_burnactual($sum1, $sum2) {
    $sql = "SELECT estimated_sum FROM burndown_snap WHERE project_id='$sum1' AND name='$sum2'";
    $burn_array = ();
    $result = $conn->query($sql);
    if ($result->num_rows > 0) {
        while($row = $result->fetch_assoc()) {
            $burn_array[] = $row["estimated_sum"];
        }
    }
    return implode(',', $burn_array);
}

Then you call the function:

$burn_actual = get_burnactual($proj, $name);
echo $burn_actual;