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?

1 Answer 1

11
$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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.