如何将列的所有行添加到变量中?

Imagine I had an "id" column and each of its rows contained a number. Lets say I have 3 rows at the moment. row 1 contains 1111, row 2 contains 2222, row 3 contains 3333.

I want to get the row values into a variable, and separate each row's data by a comma. The final result I expect is $variable = 1111,2222,3333.

I got this far code-wise:

<?php

    mysql_connect("localhost", "root", "") or die(mysql_error());
    mysql_select_db("streamlist") or die(mysql_error());

    $sql = mysql_query("SELECT web_id FROM streams") or die(mysql_error());

        while($row = mysql_fetch_array($sql)) {

            $streamlist = $row['web_id'].",";

            echo $streamlist;

        }

?>

The problem is that I then need each row's information singularly:

<?php

    $numbers = explode(',', $streamlist);
    $firstpart = $numbers[0];

    echo $firstpart;

?>

And the above code doesn't work inside the while() statement, nor does this:

<?php

    mysql_connect("localhost", "root", "") or die(mysql_error());
    mysql_select_db("streamlist") or die(mysql_error());

    $sql = mysql_query("SELECT web_id FROM streams") or die(mysql_error());

        while($row = mysql_fetch_array($sql)) {

            $streamlist = $row['web_id'].",";

        }

    $numbers = explode(',', $streamlist);
    $firstpart = $numbers[0];

    echo $firstpart;

?>

So basically, how can I get all of the information of the rows into a variable, and make them seperated by commas, in order to then get each number singularly?

mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("streamlist") or die(mysql_error());

$sql = mysql_query("SELECT web_id FROM streams") or die(mysql_error());
while($row = mysql_fetch_assoc($sql)) {

    $streamlist[] = $row['web_id'];

}

foreach ($streamlist as $row) {

    // Do whatever you want with the data
    echo $row.',';

}

$comma_separated = implode(",", $streamlist);

The $streamlist scope doesn't seem right. Try:

$streamlist = '';
while($row = mysql_fetch_array($sql)) {

        $streamlist .= $row['web_id'].",";

    }

You're on the right track, try this on for size:

<?php

    mysql_connect("localhost", "root", "") or die(mysql_error());
    mysql_select_db("streamlist") or die(mysql_error());

    $sql = mysql_query("SELECT web_id, nextrow, nextrow2 FROM streams") or die(mysql_error());

    while($row = mysql_fetch_array($sql, MYSQL_NUM)){
        // $array_data will contain the array with all columns from the query (usable for your individual data needs as well)
        $array_data[] = $row;
        $var_string .= implode(",",$row);
        // $var_string will contain your giant blob comma separated string    
    }   
echo "<pre>"; print_r($array_data);echo "</pre>";
echo $var_string;
// These are for outputting the results
?>