Forum Moderators: coopster

Message Too Old, No Replies

php array help

need a lot of help..

         

cremesoda201

2:00 am on Feb 17, 2005 (gmt 0)

10+ Year Member



Alright, so here is the situation.

I am pulling a recordset from a database and I want all of the data from one column to collect into a single variable i can echo. Is there anyway to collect everything into one string I can parse out?

hakre

2:09 am on Feb 17, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



if you want to echo, i think print_r($row) should do the job. if you need to have it in one line, check the array functions for merging one array like implode().

cremesoda201

2:24 am on Feb 17, 2005 (gmt 0)

10+ Year Member



Here is what I have so far. But it is repeating the same record for how many records there are. I want it to display each city it pulls.


<?PHP

for ($x=0;$x<$totalRows_cities;$x++) {
$citylist .= $row_cities['city'];
};

?>

<?PHP echo $citylist;?>

coopster

4:08 am on Feb 17, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, cremesoda201.

You need to do the concatenation within your while [php.net] loop.

$my_var = ''; // initialize 
while ($row = fetch_array from database result set) {
$myvar .= ',' . $row['my_column']; // comma-separated values
}