Q. 1) Create a table student having attributes(rollno, name, class) containing atleast 5 recodes . Using
codeigniter, display all its records. [Marks 15]
CREATE TABLE student (
rollno INT PRIMARY KEY,
name VARCHAR(255),
class VARCHAR(50)
);
<?php
class Student_model extends CI_Model {
public function __construct() {
parent::__construct();
$this->load->database(); // Load the database library
}
// Function to fetch all records from the student table
public function get_all_students() {
$query = $this->db->get('student');
return $query->result(); // Return all records
}
}
?>
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Student extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->model('student_model'); // Load the Student_model
}
// Function to display all records from the student table
public function display_records() {
$data['students'] = $this->student_model->get_all_students();
$this->load->view('student_records', $data); // Load the view file
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Student Records</title>
</head>
<body>
<h1>Student Records</h1>
<table border="1">
<tr>
<th>Roll No</th>
<th>Name</th>
<th>Class</th>
</tr>
<?php foreach ($students as $student): ?>
<tr>
<td><?php echo $student->rollno; ?></td>
<td><?php echo $student->name; ?></td>
<td><?php echo $student->class; ?></td>
</tr>
<?php endforeach; ?>
</table>
</body>
</html>
Q. 2) Consider any text paragraph. Preprocess the text to remove any special characters and
digits.
import re
Sample text paragraph
text = "Consider any text paragraph. Preprocess the text to remove any special characters and digits."
Remove special characters and digits using regular expressions
clean_text = re.sub(r'[^a-zA-Z\s]', '', text)
print("Original Text:")
print(text)
print("\nText after preprocessing:")
print(clean_text)