Last active
December 18, 2018 13:33
-
-
Save dkarandana/d1a24cbab530b432b7d58b1642979e74 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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