How to Display Result of XML in HTML table

1

I have a page that displays a query in xml and json , I would like to know how I can show that information in an html table, either on the same page or in a new one.

I leave the code that I currently have.

$format = (isset($_GET['format'])?$_GET['format']:"xml");
$sql_query = "SELECT * FROM guias"; 
$resultset = mysqli_query($conn, $sql_query) or die("database error:". mysqli_error($conn));
$products = array(); 


if(mysqli_num_rows($resultset)) 
    { while($product = mysqli_fetch_assoc($resultset)) 
        { $products[] = array('product'=>$product);

        }
    }

/* output result in required format */
if($format == 'json') 
    {
        header('Content-type: application/json');
        echo json_encode(array('products'=>$products));
    } else 
        if($format == 'xml') 
            {
                header('Content-type: text/xml');
                echo '<products>';
                foreach($products as $index => $product) 

                {

                    if(is_array($product)) 
                        {           

                            foreach($product as $key => $value) 
                                {
                                    echo '<',$key,'>';
                                    if(is_array($value)) 
                                        {
                                            foreach($value as $tag => $val) 
                                                {
                                                    echo '<',$tag,'>',htmlentities($val),'</',$tag,'>';
                                                }
                                        }
                                        echo '</',$key,'>';

                                }
                        }

            }

echo '</products>';
}
@mysqli_close($link);
}
?>
    
asked by Felipe 23.03.2018 в 00:20
source

0 answers