Member Avatar for FakeTales

basically i am using xpath for a search query, the results display like this

Array ( [0] => SimpleXMLElement Object ( [TITLE] => Empire Burlesque [ARTIST] => Bob Dylan [COUNTRY] => USA [COMPANY] => Columbia [PRICE] => 10.90 [YEAR] => 1985 ) 
[1] => SimpleXMLElement Object ( [TITLE] => Greatest Hits [ARTIST] => Dolly Parton [COUNTRY] => USA [COMPANY] => RCA [PRICE] => 9.90 [YEAR] => 1982 ) 
[2] => SimpleXMLElement Object ( [TITLE] => Hard rains gonna fall [ARTIST] => Bob Dylan [COUNTRY] => USA [COMPANY] => Columbia [PRICE] => 5.50 [YEAR] => 1962 ) )

is it possible to get this displaying in a table so the header rows would show: Title, Artist, Country, Company, Price , Year

assumint that the variable name of your array above is $array

$index = 1;
echo '<table>';
foreach($array as $val){
    if($index==1){
        echo '<tr>';
        foreach($val as $key => $value ){
            echo '<th>'.$key.'</th>';
        }
        echo '<tr>';
    }
        echo '<tr>';
        foreach($val as $key => $value){
            echo '<td>'.$value.'</td>';
        }
        echo '</tr>';
    $index++;

}
echo '</table>';
Member Avatar for FakeTales

Brilliant i managed to get the actual data into rows but was still trying to figure out how to get the header data in thanks code739

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.