Guest User

Untitled

a guest
Dec 10th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.37 KB | None | 0 0
  1. <?php
  2.     // Create the Database Connection
  3.     $dsn = 'mysql:host=localhost;dbname=nei_intra';
  4.     $dbuser = 'foo';
  5.     $dbpass = 'bar';
  6.  
  7.     // Make the connection to the database, create a database handle.
  8.     // Let's also make sure that the error handles are in place.
  9.     $conn = new PDO ( $dsn, $dbuser, $dbpass );
  10.     $conn->setAttribute ( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
  11.  
  12.     // Create a SQL statement to query the data we're looking for.
  13.     // Use this statement to determine how many rows we're dealing with.
  14.     $archsql = "SELECT * FROM $arch_tbl";
  15.  
  16.     // Perform the query, return the data, store it in the varible $archNumRows.
  17.     // Catch any errors along the way.
  18.     try
  19.     {
  20.         $archrows = $conn->query ( $archsql );
  21.         $rows = $archrows->fetchAll ();
  22.         $archNumRows = count ( $rows );
  23.     }
  24.     catch ( PDOEXCEPTION $e )
  25.     {
  26.         print ( "The archive query failed.\n" );
  27.         print ( "getCode returns: " . $e->getCode () . "\n" );
  28.         print ( "getMessage returns: " . $e->getMessage () . "\n" );
  29.     }
  30.  
  31.     // Let's set a varible that can be used to alternate the color of the
  32.     // rows of the table.
  33.     $i = 0;
  34.  
  35.     // At this point we should some data from the database to display.
  36.     // Let's see if we can create a table to do that.
  37.     print "<table>
  38.        <tr>
  39.            <th>ID</th>
  40.            <th>Box Number</th>
  41.            <th>Job Number</th>
  42.            <th>Description</th>
  43.        </tr>\n";
  44.  
  45.     // Run through a while loop to spit out the data we've collected.
  46.     while ( $row = $archrows->fetch(PDO::FETCH_ASSOC) ) {
  47.         $i ++;
  48.         if ($i <= 2) {
  49.             print "<tr>";
  50.             print "<td>" . $row['id'] . "</td>";
  51.             print "<td>" . $row['box_number'] . "</td>";
  52.             print "<td>" . $row['job number'] . "</td>";
  53.             print "<td>" . $row['description'] . "</td>";
  54.             print "</tr>\n";
  55.         } else {
  56.             print "<tr class=\"hilight\">";
  57.             print "<td>" . $row['id'] . "</td>";
  58.             print "<td>" . $row['box_number'] . "</td>";
  59.             print "<td>" . $row['job_number'] . "</td>";
  60.             print "<td>" . $row['description'] . "</td>";
  61.             print "</tr>\n";
  62.             $i = 0;
  63.         }
  64.     }
  65.  
  66.     // Now that the table data has been displayed, let's close the table.
  67.     print "</table>";
  68. ?>
Add Comment
Please, Sign In to add comment