PHP PB2 PB3
PHP PB2 PB3
Utilize HTML for the user interface and PHP for the backend logic. Dynamically generate the
required number of textboxes based on the specified number of rows and columns.
<!DOCTYPE html>
<html lang="en">
<head>
<title>Matrix Operations</title>
<style>
table {
border-collapse: collapse;
margin-bottom: 20px;
}
th, td {
padding: 8px;
text-align: center;
border: 1px solid #ddd;
}
</style>
</head>
<body>
<h2>Matrix Operations</h2>
<form action="" method="post">
<label for="rows1">Rows (Matrix 1):</label>
<input type="number" id="rows1" name="rows1" min="1" required>
<label for="cols1">Columns (Matrix 1):</label>
<input type="number" id="cols1" name="cols1" min="1" required><br><br>
function displayMatrix($matrix) {
echo "<table>";
foreach ($matrix as $row) {
echo "<tr>";
foreach ($row as $value) {
echo "<td>$value</td>";
}
echo "</tr>";
}
echo "</table>";
}
?>
</body>
</html>
PB3. Write a PHP program that implements a class to add and find the difference of two
distance values given in feet and inches. The user inputs are collected through an HTML form.
PB3.html
<!DOCTYPE html>
<html lang="en">
<head>
<title>Distance Calculator</title>
</head>
<body>
<h2>Distance Calculator</h2>
<form action="PB3.php" method="post">
<label for="feet1">Feet 1:</label>
<input type="number" id="feet1" name="feet1" required> feet
<input type="number" id="inches1" name="inches1" required> inches<br><br>
PB3.php
<?php
class Distance {
public $feet;
public $inches;
if ($in < 0) {
$ft--; // Reduce a foot
$in += 12; // Add 12 inches
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$feet1 = $_POST["feet1"];
$inches1 = $_POST["inches1"];
$feet2 = $_POST["feet2"];
$inches2 = $_POST["inches2"];
// Adding distances
$sum = $distance1->add($feet2, $inches2);
// Finding difference
$difference = $distance1->subtract($feet2, $inches2);
echo "<h2>Result</h2>";
echo "<p>Sum: " . $sum->getDistance() . "</p>";
echo "<p>Difference: " . $difference->getDistance() . "</p>";
}
?>