Skip to content

Instantly share code, notes, and snippets.

@dpmckenzie
Created September 27, 2012 04:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dpmckenzie/3792147 to your computer and use it in GitHub Desktop.
Save dpmckenzie/3792147 to your computer and use it in GitHub Desktop.
Wordpress page template for creating a simple listing of my database contents. Note that I have redacted my login info.
<?php
/**
* Template Name: Custom database tables
* @package WordPress
* @subpackage Coraline
* @since Coraline 1.0
*/
coraline_set_full_content_width();
get_header(); ?>
<div id="content-container" class="full-width">
<div id="content" role="main">
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<h1 class="entry-title"><?php the_title(); ?></h1>
<div class="entry-content">
<?php the_content(); ?>
<?php
// The connection into my database and the code for creating the listing of all items.
$conn = new mysqli('[redacted]', '[redacted]', '[redacted]', '[redacted]');
// check connection
if (mysqli_connect_errno()) {
exit('Connect failed: '. mysqli_connect_error());
}
/*open connection*/
/* Select the fields */
$sql = "SELECT case_no, claim_total, final_total FROM claim";
/* Perform the query */
$result = $conn->query($sql);
/* Display */
if ($result->num_rows > 0) {
/* output data of each row from $result */
while($row = $result->fetch_assoc()) {
echo '<br /> <b>Case number:</b> ', $row['case_no'], '<br /> <b>Claim Total:</b> $', $row['claim_total'], '<br /> <b>Total Verdict:</b> $', $row['final_total'], '<br />';
}
}
else {
echo '0 results';
}
$conn->close(); // close the connection
?>
<?php wp_link_pages( array( 'before' => '<div class="page-link">' . __( 'Pages:', 'coraline' ), 'after' => '</div>' ) ); ?>
<?php edit_post_link( __( 'Edit', 'coraline' ), '<span class="edit-link">', '</span>' ); ?>
</div><!-- .entry-content -->
</div><!-- #post-## -->
<?php if ( comments_open() ) comments_template( '', true ); ?>
<?php endwhile; ?>
</div><!-- #content -->
</div><!-- #content-container -->
<?php get_footer(); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment