PHP/MySQL Database/Table Column — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
Admin (обсуждение | вклад) м (1 версия) |
(нет различий)
|
Текущая версия на 07:06, 26 мая 2010
Reference columns by name
<html>
<body>
<?php
$host="mysql153.secureserver.net";
$uname="wbex";
$pass="password";
$database="wbex";
$tablename="Employee";
$connection= mysql_connect ($host, $uname, $pass) or die ("Database connection failed! <br>");
$result=mysql_select_db ($database) or die ("Database could not be selected");
$query = "SELECT * from ". $tablename;
$result = mysql_query ($query);
echo "<table>";
echo " <tr>";
echo " <td> <center><b>ID</b></center></td>";
echo " <td> <center><b>First Name</b></center></td>";
echo " <td> <center><b>Last Name</b></center></td>";
echo " </tr>";
while ($row=mysql_fetch_array ($result))
{
echo " <tr>\n";
echo " <td>". $row["ID"]. "</td>";
echo " <td>". $row["FirstName"]. "</td>";
echo " <td>". $row["LastName"]. "/td>";
echo " </tr>";
}
echo "</table>";
?>
</body>
</html>
Reference table columns by index
<html>
<body>
<?php
$host="mysql153.secureserver.net";
$uname="wbex";
$pass="password";
$database="wbex";
$tablename="Employee";
$connection= mysql_connect ($host, $uname, $pass) or die ("<br>Database connection failed! <br>");
$result=mysql_select_db ($database) or die ("<br>Database could not be selected<br>");
$query = "SELECT * from Employee";
$result = mysql_query ($query);
echo "<table>";
echo "<tr";
echo " <td> <center><b>ID </b></center></td>\n";
echo " <td> <center><b>First Name </b></center></td>\n";
echo " <td> <center><b>Last Name</b></center></td>\n";
echo " </tr>\n";
while ($row=mysql_fetch_row ($result))
{
echo " <tr>\n";
echo " <td>$row[0] </td>\n";
echo " <td>$row[1] </td>\n";
echo " <td>$row[2] </td>\n";
echo " </tr>\n";
}
echo "</table>\n";
?>
</body>
</html>