Skip to content

Instantly share code, notes, and snippets.

@vigikaran
Created June 21, 2016 18:04
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 vigikaran/22b2c9d38a1b65970d072ac7e1341031 to your computer and use it in GitHub Desktop.
Save vigikaran/22b2c9d38a1b65970d072ac7e1341031 to your computer and use it in GitHub Desktop.
<?php
// Make a MySQL Connection
mysql_connect("host", "user", "password") or die(mysql_error());
mysql_select_db("database") or die(mysql_error());
// Get all the data from the "example" table
$result = mysql_query("SELECT * FROM news LIMIT 5")
or die(mysql_error());
echo "<table border='1'>";
echo "<tr> <th>ID</th> <th>Title</th> </tr>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
// Print out the contents of each row into a table
echo "<tr><td>";
echo $row['news_id'];
echo "</td><td>";
echo $row['news_title'];
echo "</td></tr>";
}
echo "</table>";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment