Get data from database query : Database Query « MySQL Database « PHP






Get data from database query

<html>
<body>
<ul>
<?php
$cnx = mysql_connect('mysql153.secureserver.net','java2s','password');
mysql_select_db('java2s');

$employees = @mysql_query('SELECT ID, FirstName FROM Employee');
if (!$employees) {
  die('<p>Error retrieving employees from database!<br />'.
      'Error: ' . mysql_error() . '</p>');
}

while ($employee = mysql_fetch_array($employees)) {
  $id   = $employee['ID'];
  $name = htmlspecialchars($author['Name']);
  echo("$name <br>");
  echo("$id <br>");
}

?>
</ul>

</p>
</body>
</html>
           
       








Related examples in the same category

1.List Database, Table, and Field
2.Sending SQL Queries to a MySQL Database using the mysql_query () function
3.Listing All Rows and Fields in a Table
4.Finding the Number of Rows Returned by a SELECT Statement with mysql_num_rows()