Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Create the Database Connection
- $dsn = 'mysql:host=localhost;dbname=nei_intra';
- $dbuser = 'foo';
- $dbpass = 'bar';
- // Make the connection to the database, create a database handle.
- // Let's also make sure that the error handles are in place.
- $conn = new PDO ( $dsn, $dbuser, $dbpass );
- $conn->setAttribute ( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
- // Create a SQL statement to query the data we're looking for.
- // Use this statement to determine how many rows we're dealing with.
- $archsql = "SELECT * FROM $arch_tbl";
- // Perform the query, return the data, store it in the varible $archNumRows.
- // Catch any errors along the way.
- try
- {
- $archrows = $conn->query ( $archsql );
- $rows = $archrows->fetchAll ();
- $archNumRows = count ( $rows );
- }
- catch ( PDOEXCEPTION $e )
- {
- print ( "The archive query failed.\n" );
- print ( "getCode returns: " . $e->getCode () . "\n" );
- print ( "getMessage returns: " . $e->getMessage () . "\n" );
- }
- // Let's set a varible that can be used to alternate the color of the
- // rows of the table.
- $i = 0;
- // At this point we should some data from the database to display.
- // Let's see if we can create a table to do that.
- print "<table>
- <tr>
- <th>ID</th>
- <th>Box Number</th>
- <th>Job Number</th>
- <th>Description</th>
- </tr>\n";
- // Run through a while loop to spit out the data we've collected.
- while ( $row = $archrows->fetch(PDO::FETCH_ASSOC) ) {
- $i ++;
- if ($i <= 2) {
- print "<tr>";
- print "<td>" . $row['id'] . "</td>";
- print "<td>" . $row['box_number'] . "</td>";
- print "<td>" . $row['job number'] . "</td>";
- print "<td>" . $row['description'] . "</td>";
- print "</tr>\n";
- } else {
- print "<tr class=\"hilight\">";
- print "<td>" . $row['id'] . "</td>";
- print "<td>" . $row['box_number'] . "</td>";
- print "<td>" . $row['job_number'] . "</td>";
- print "<td>" . $row['description'] . "</td>";
- print "</tr>\n";
- $i = 0;
- }
- }
- // Now that the table data has been displayed, let's close the table.
- print "</table>";
- ?>
Add Comment
Please, Sign In to add comment