Tell me more ×
WordPress Answers is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am using a formbuilder plugin in Wordpress which submits the form input to the database as XML data. Now I would like to fetch that data and have it displayed in another page. I have started trying simpleXML to achieve this but now I have hit a road bump.

The XML data that appears in each row of the database follows this format:

<form>
    <FormSubject>Report</FormSubject>
    <FormRecipient>****@***.com</FormRecipient>
    <Name>admin</Name>
    <Department>test</Department>
    <Value>1000</Value>
    <Comments>test</Comments>
    <Page>http://***.com</Page>
    <Referrer>http://****.com</Referrer>
</form>

I have previously managed to fetch the data that I need using simpleXML from an XML string of the same markup which is in the database but now my question is, how do I do this with a loop for each row in the database?

When the following code is run, wordpress displays a blank page meaning that there is an error:

<?php
global $wpdb;
$statistics = $wpdb->get_results("SELECT * FROM wpformbuilder_results WHERE form_id = '00000000000000000001';");
echo "<table>";
foreach($statistics as $statistic){
$string = $statistic->xmldata
$xml = simplexml_load_string($string);
$Name = (string) $xml->Name;
$Department = (string) $xml->Department;
$Value = (string) $xml->Value;
$Comments = (string) $xml->Comments;

echo "<tr>";
echo "<td>".$statistic->timestamp."</td>";
echo "<td>".$Name."</td>";
echo "<td>".$Department."</td>";
echo "<td>".$Value."</td>";
echo "<td>".$Comments."</td>";
echo "</tr>";
}
echo "</table>";

?>
share|improve this question
1  
This seems like more of a PHP question than WordPress and if so it is off-topic here. – Joseph Jan 27 at 4:31

1 Answer

You are missing a semicolon from this line:

$string = $statistic->xmldata;
share|improve this answer
Thank you that helped but there must be something else wrong because it still doesn't work. – mhcodner Jan 27 at 4:43
What error is showing up in your logs? – Joseph Jan 27 at 4:45
I don't know, where can I find the logs within wordpress? I am new to wordpress and still relatively new to PHP – mhcodner Jan 27 at 4:47
1  
The logs will be somewhere on your server, not in WordPress. You will need to consult your host to find out where they are located. You can also try adding define( 'WP_DEBUG', true ) to your wp-config.php file. – Joseph Jan 27 at 4:50

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.