I have a SQL database named result having table res and sub.
For example,
The res table column and contents are:
sno regno name sub1 sub2 sub3 sub4 sub5
1 1DU12CS100 student1 70 80 85 70 90
2 1DU12CS101 student2 75 70 90 80 70
3 1DU12EE015 student3 80 85 70 50 65
4 1DU14CS123 student4 88 85 85 90 70
5 1DU13ME050 student5 85 90 70 60 55
The sub table column and contents are:
Sno batname sub1 sub2 sub3 sub4 sub5
1 1DU12CS Maths English Hindi Urdu Social
2 1DU12ME Sanksrit Chinese Japanese French Dutch
3 1DU12EE Circuit Electrical Electronic Maths Hindi
4 1DU14CS Hindi Maths Urdu Science Maths
5 1DU13ME Computer Maths Electrical Mechanical GK
I want to fetch some value from table res and some from table sub and display in php/html table.
1DU12CS100 --
1DU ->college code
12 ->Student admission year
CS ->computer science
100->roll no of student
When someone enters 1DU12CS100 in php form, the result should be displayed like this...
Subjects Marks
Maths 70
English 80
Hindi 85
Urdu 70
Social 90
And when someone enters 1DU13ME050, then the display should be
Subjects Marks
Computer 85
Maths 90
Electrical 70
Mechanical 60
GK 55
The php form code is
<!DOCTYPE HTML>
<html>
<body>
<form action="result.php" method="post">
Enter your Reg No: <input type="text" name="regno"><br>
<input type="submit">
</form>
</body>
</html>
The result.php code is // What changes should be made in this php code ??
<?php
$servername = "localhost";
$username = "myresult";
$password = "abcdefg";
$dbname = "myresult";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$regno = mysqli_real_escape_string($conn, $_POST['regno']);
$sql = "SELECT * FROM myresult WHERE regno LIKE '$regno'"; // What changes should be here ??
$result = $conn->query($sql);
$columns = array();
$resultset = array();
while ($row = mysql_fetch_assoc($result)) {
if (empty($columns)) {
$columns = array_keys($row);
}
$resultset[] = $row;
}
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "{$row['sub1']}{$row['sub2']}"; // What changes should be made here??
// Print the data
while($row = mysql_fetch_row($result)) {
foreach($row as $_column) {
echo "{$_column}";
}
}
}
} else {
echo "Result Not Found";
}
$conn->close();
?>
regnofield; unless you are forced to (this looks like a remnant of old punch card style data management), I'd restructure your data.