8. (B) Write a PHP program to create a database named “College”. Create a table named “Student” with following fields (sno, sname, percentage). Insert 3 records of your choice. Display the names of the students whose percentage is between 35 to 75 in a tabular format.

8. (B) Write a PHP program to create a database named “College”. Create a table named “Student” with following fields (sno, sname, percentage). Insert 3 records of your choice. Display the names of the students whose percentage is between 35 to 75 in a tabular format.

<html>
<head>
<title>Database insert and select</title>
</head>
<body>
<?php
$con=mysql_connect("localhost","root","");
if(!$con)
die('could not connect:'.mysql_error());
if(mysql_query("create database College",$con))
echo"Database Created successfully";
else
echo "Error creating database:".mysql_error();
mysql_select_db("College",$con);
$query="create table student(sno smallint,sname varchar(50),percentage decimal(7,2))";
if(mysql_query($query,$con))
echo"Table Created successfully";
else
echo "Error creating table:".mysql_error();
$query1="insert into student values(101,'Allen',78)";
if(mysql_query($query1,$con))
echo"Record 1 inserted successfully";
else
echo "Error inserting record 1:".mysql_error();
$query2="insert into student values(102,'Smith',45)";
if(mysql_query($query2,$con))
echo"Record 2 inserted successfully";
else
echo "Error inserting record 2:".mysql_error();
$query3="insert into student values(103,'Scott',63.2)";
if(mysql_query($query3,$con))
echo "Record 3 inserted successfully";
else
echo "Error inserting record 3:".mysql_error();
$sql="select * from student where percentage>=35 and percentage<=75";
$result=mysql_query($sql,$con);
if(mysql_num_rows($result)>0)
{
echo "<table border='1'> <tr><th>Sno</th><th>Sname</th><th>Percentage</th></tr>";
while($row=mysql_fetch_assoc($result))
{
echo "<tr>";
echo "<td>".$row['sno']."</td>";
echo "<td>".$row['sname']."</td>";
echo "<td>".$row['percentage']."</td>";
echo "</tr>";
}
echo "</table>";
}
else
{
echo "Table is empty";
}
mysql_close($con);
?>
</body>
</html>
8. (B) Write a PHP program to create a database named “College”. Create a table named “Student” with following fields (sno, sname, percentage). Insert 3 records of your choice. Display the names of the students whose percentage is between 35 to 75 in a tabular format. 8. (B) Write a PHP program to create a database named “College”. Create a table named “Student” with following fields (sno, sname, percentage). Insert 3 records of your choice. Display the names of the students whose percentage is between 35 to 75 in a tabular format. Reviewed by admin on December 24, 2019 Rating: 5

No comments:

Powered by Blogger.