tags:

views:

141

answers:

1

Ok so I have the following code. I'm trying to output some xml so that it can be read with jQuery, but for whatever reason, when I try to add an element in the array to a variable, it just turns the variable to 0. I did a print_r() on the array, and it's normal.

Code

if ($content == "tables") {
    $result = mysql_query("show tables");
$xml = "<tables>";
    while ($row = mysql_fetch_assoc($result)) {
     print_r($row);
     echo "<br />";
     $xml += "<table>" . $row['Tables_in_blog'] . "</table>";
    }
    //header('Content-type: text/xml');
    echo $xml;
}

Output

Array ( [Tables_in_blog] => post )
Array ( [Tables_in_blog] => posts )
0

Does anyone know why it would do this?

+11  A: 
$xml += "<table>" . $row['Tables_in_blog'] . "</table>";

That's the offender. Try concatenation:

$xml .= "<table>" . $row['Tables_in_blog'] . "</table>";

You mistakenly used += instead of .= for concatenation. This triggered PHP to convert the values to numbers (resulting in 0) and adding them.

Konrad Rudolph