Skip to content

Instantly share code, notes, and snippets.

@dkarandana
Last active December 18, 2018 13:33
Show Gist options
  • Save dkarandana/d1a24cbab530b432b7d58b1642979e74 to your computer and use it in GitHub Desktop.
Save dkarandana/d1a24cbab530b432b7d58b1642979e74 to your computer and use it in GitHub Desktop.
<?php
require 'connections.php';
$sql = "SELECT * FROM movies";
/* mysqli is the connection we build in the connections.php */
$results = $mysqli->query( $sql );
if ( ! $results ) {
// Oh no! The query failed.
echo "Error: Our query failed to execute and here is why: " . PHP_EOL;
echo "Query: " . $sql . PHP_EOL;
echo "Errno: " . $mysqli->errno . PHP_EOL;
echo "Error: " . $mysqli->error . PHP_EOL;
exit;
}else{
$row = 0;
$movieRecords ='';
/******************************************
Hold Multiple Records as OBJECT
*******************************************/
while ( $movie = $results->fetch_object() ) {
$classes = ( ++$row % 2 == 0 ) ? 'even' : 'odd';
$movieRecords .= <<<TABLE
<tr class="{$classes}">
<td>{$movie->id}</td>
<td><img src="{$movie->thumbnail}" alt="{$movie->name}"</td>
<td>{$movie->name}</td>
<td>{$movie->intro}</td>
<td>{$movie->votes}</td>
<td>{$movie->ratings}</td>
</tr>
TABLE;
}
echo <<<EOD
<h3>Movie Records</h3>
<table border=1>
<thead>
<td>Id</td>
<td>Thumb</td>
<td>Name</td>
<td>Intro</td>
<td>Votes</td>
<td>Rating</td>
</thead>
<tbody>
{$movieRecords}
</tbody>
</table>
EOD;
$results->free();
$mysqli->close();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment