0

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

2
Contributors
2
Replies
3
Views
4 Years
Discussion Span
Last Post by FakeTales
Featured Replies
  • 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>'; Read More

1

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>';
0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.