Pull in and Display MySQL Data with PHP

Having access to a database with existing data, the simple PHP program below will display a table of entries derived from the selected query.

<?php

$con = mysql_connect("localhost","USERNAME","PASSWORD");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("DATABASE", $con);

$result = mysql_query("SELECT * FROM TABLE");

echo "<table border='0'>
<tr>
<th>Query(s)</th>
</tr>";

while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . "<a href=\"./local/\">" . $row['query'] . "</a>" .
"</td>";
  echo "</tr>";
  }
echo "</table>";

mysql_close($con);

?>

The items in green must match your server settings.  Also, the $result variable is key to shaping what data actually gets pulled.

[REF_URL: http://www.w3schools.com/PHP/php_mysql_select.asp%5D

Advertisements

Tags:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s


%d bloggers like this: