workflow
CREATE DATABASE result_management;
USE result_management;
CREATE TABLE students (
id INT(11) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(50) NOT NULL,
email VARCHAR(100) NOT NULL,
phone VARCHAR(20) NOT NULL,
address VARCHAR(100) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE subjects (
id INT(11) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(50) NOT NULL,
description VARCHAR(255),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE results (
id INT(11) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
student_id INT(11) UNSIGNED NOT NULL,
subject_id INT(11) UNSIGNED NOT NULL,
marks INT(3) UNSIGNED NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (student_id) REFERENCES students(id),
FOREIGN KEY (subject_id) REFERENCES subjects(id)
);
Here's the PHP script to retrieve student and subject information
We can create a separate file for database connection and include it in your other PHP files to avoid repeating the same code.
Here's an example of a database connection file named "db_connect.php":
You can include this file in your PHP scripts using the include or require statement
Here's the code that includes the database connection file:
Note that the require_once('db_connect.php'); line includes the file containing the database connection code. Make sure to update the file name and path to match the location of your db_connect.php file.
In above two script, we first connect to the database using the mysqli_connect() function. We then execute two separate SQL queries to retrieve all the student information and subject information from their respective tables using the mysqli_query() function. The results of these queries are stored in PHP variables using the mysqli_fetch_all() function.
Finally, we close the database connection using the mysqli_close() function. Note that the database connection details such as host, username, password, and database name may vary depending on your specific configuration.
Last updated