-1

I want the table header like this: NUME, DECEDATI etc. I tried with echo also and it doesn't work. Please help me!

PHP code:

    <?php
    print "<table";
    print "<tr>";
    print "<th>NUME  </th>";
    print "<th>  DECEDATI   </th>";
    print "<th>  RANITI   </th>";
    print "<th>  DISPARUTI   </th>";
    print "<th>  CLADIRI DISTRUSE  </th>";
    print "<th>  DURATA   </th>";
    print "<th>  MAGNITUDINE   </th>";
    print "<th>  ADANCIME   </th>";
    print "<th>  PAGUBE MATERIALE   </th>";
    print "<th>  NUMAR REPLICI  </th>";
    print "</tr>";
    print "</table>";
    $conn = oci_connect('student', 'STUDENT', 'localhost/XE');
    if (!$conn) {
        $e = oci_error();
        trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
    }

    // Prepare the statement
    $stid = oci_parse($conn, "SELECT * FROM nepal ORDER BY ".$_GET['categorie']." ".$_GET['ordine']);
    if (!$stid) {
        $e = oci_error($conn);
        trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
    }

    // Perform the logic of the query
    $r = oci_execute($stid);
    if (!$r) {
        $e = oci_error($stid);
        trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
    }

    // Fetch the results of the query
    print "<table border='1'>\n";
    while ($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) {
        print "<tr>\n";
        foreach ($row as $item) {
            print "    <td>" . ($item !== null ? htmlentities($item, ENT_QUOTES) : "&nbsp;") . "</td>\n";
        }
        print "</tr>\n";
    }
    print "</table>\n";

    oci_free_statement($stid);
    oci_close($conn);

    ?>

The display of my code containts the body of the table without the table header.

2 Answers2

0

Assuming that the table headers should be part of the same table that displays the actual data then you would probably want to try something like this.

<?php

    echo "
    <table>
        <tr>
            <th>NUME</th>
            <th>DECEDATI</th>
            <th>RANITI</th>
            <th>DISPARUTI</th>
            <th>CLADIRI DISTRUSE</th>
            <th>DURATA</th>
            <th>MAGNITUDINE</th>
            <th>ADANCIME</th>
            <th>PAGUBE MATERIALE</th>
            <th>NUMAR REPLICI</th>
        </tr>";


    $conn = oci_connect('student', 'STUDENT', 'localhost/XE');
    if( !$conn ) {
        $e = oci_error();
        trigger_error( htmlentities( $e['message'], ENT_QUOTES ), E_USER_ERROR );
    }

    $stid = oci_parse( $conn, "SELECT * FROM nepal ORDER BY ".$_GET['categorie']." ".$_GET['ordine'] );
    if( !$stid ) {
        $e = oci_error( $conn );
        trigger_error( htmlentities( $e['message'], ENT_QUOTES ), E_USER_ERROR );
    }

    // Perform the logic of the query
    $r = oci_execute( $stid );
    if( !$r ) {
        $e = oci_error( $stid );
        trigger_error( htmlentities( $e['message'], ENT_QUOTES ), E_USER_ERROR );
    }

    // Fetch the results of the query
    while( $row = oci_fetch_array( $stid, OCI_ASSOC+OCI_RETURN_NULLS ) ) {
        $value=$item !== null ? htmlentities( $item, ENT_QUOTES ) : "&nbsp;";
        echo "
        <tr>
            <td>$value</td>
        </tr>";
    }


    oci_free_statement( $stid );
    oci_close( $conn );

    echo "</table>";
?>
Professor Abronsius
  • 33,063
  • 5
  • 32
  • 46
-1
print "<table"; 

needs to be

print "<table>";

Note the missing >

Qirel
  • 25,449
  • 7
  • 45
  • 62
David
  • 369
  • 2
  • 4
  • 14