<?
// connect to the mysql server on localhost
$mysql = mysql_connect("192.168.8.3", "naveen", "a")
or die("could not connect to mysql");
// execute the MySQL query, grab the result in $result
$result = mysql_db_query("naveen", "SELECT * FROM student")
or die("query failed ");
?>
<html>
<head>
<title>PHP and MySQL</title>
</head>
<body bgcolor="CYAN">
We executed: <b> SELECT * FROM student</b>
<hr>
We found <b><?echo mysql_num_rows($result); ?></b> rows.
<h3>Query result</h3>
<br>
<table border=2>
<tr>
<td>USN</td>
<td>NAME</td>
<td>BRANCH</td>
<td>SEM</td>
<td>CGPA</td>
</tr>
<?
//loop through each row
while ($array = mysql_fetch_row($result))
{
echo "<tr>";
echo "<td>$array[0]</td>";
echo "<td>$array[1]</td>";
echo "<td>$array[2]</td>";
echo "<td>$array[3]</td>";
echo "<td>$array[4]</td>";
echo "</tr>";
}
?>
</table>
</body>
</html>
<?
// we are all done, so close the MySQL connection
mysql_close($mysql);
?>
OUT PUT:
We executed: SELECT * FROM student
We found 7 rows.
We found 7 rows.
Query result
| USN | NAME | BRANCH | SEM | CGPA |
| 2sd02is006 | jhon | cse | 7 | 8.75 |
| 2sd02is007 | jackie | ec | 5 | 7.75 |
| 2sd02is008 | tom | ee | 5 | 6.75 |
| 2sd02is008 | jerry | ise | 7 | 7.77 |
| 2sd02is015 | ford | ise | 5 | 5.55 |
| ytyutyu | ee | ee | 2 | 5.55 |
| 2sd05is099 | nnnnn | ise | 7 | 9.99 |
No comments:
Post a Comment