By GokiSoft.com| 18:38 21/05/2022|
Học PHP

[Examination] Thi kết thúc khóa học PHP - Đề 1

Đề Thi Môn PHP

Phản hồi từ học viên

5

(Dựa trên đánh giá ngày hôm nay)

nguyễn Sử [T2008A]
nguyễn Sử

2021-06-30 09:12:51



Route::get('/library/index',[\App\Http\Controllers\Library\LibraryController::class,"Book"]);



Nguyễn Hữu Hiếu [T2008A]
Nguyễn Hữu Hiếu

2021-06-30 09:12:24



<?php
define('HOST', 'localhost');
define('USERNAME', 'root');
define('PASSWORD', '');
define('DATABASE', 'book');






<?php 
	require_once('config.php');

	function createDatabase() {
	// Them du lieu vao database
	//B1. Mo ket noi toi database
	$conn = mysqli_connect(HOST, USERNAME, PASSWORD);
	mysqli_set_charset($conn, 'utf8');

	
	$sql = "create database if not exists ".DATABASE."  DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci";
	mysqli_query($conn, $sql);

	//B3. Dong ket noi database
	mysqli_close($conn);
	}


	function execute($sql) {
	//save data -> database (product)
	//B1. Mo ket noi toi database
	$conn = mysqli_connect(HOST, USERNAME, PASSWORD, DATABASE);
	mysqli_set_charset($conn, 'utf8');

	//B2. Thuc thi query (select, insert, update, delete)
	mysqli_query($conn, $sql);

	//B3. Dong ket noi database
	mysqli_close($conn);
}

function executeResult($sql) {
	//save data -> database (product)
	//B1. Mo ket noi toi database
	$conn = mysqli_connect(HOST, USERNAME, PASSWORD, DATABASE);
	mysqli_set_charset($conn, 'utf8');

	//B2. Thuc thi query (select, insert, update, delete)
	$data      = [];
	$resultset = mysqli_query($conn, $sql);
	while (($row = mysqli_fetch_array($resultset, 1)) != null) {
		$data[] = $row;
	}

	//B3. Dong ket noi database
	mysqli_close($conn);

	return $data;
}


 



<?php 
	require_once('dbhelper.php');

	if(!empty($_POST)) {
	createDatabase();

	$sql1 = "create table book (
	bookid int(11) primary key not null auto_increment,
	authorid int(11) not null,
	title varchar(55) not null,
	isbn varchar(25) not null,
	pub_year smallint(6) not null,
	available tinyint(4) not null)  ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci";
	execute($sql1);

	$sql2 = "insert into book(bookid, authorid, title, isbn, pub_year, available) 
values
(1, 2, "Book 1", "isbn 1", 2011, 1),
(2, 1, "Book 2", "isbn 1", 2011, 1),
(3, 4, "Book 3", "isbn 1", 2011, 1),
(4, 3, "Book 4", "isbn 1", 2011, 1),
(5, 3, "Book 5", "isbn 1", 2011, 1) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci";
	execute($sql2);
}


 ?>

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>Library</title>
	<!-- Latest compiled and minified CSS -->
	<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">

	<!-- jQuery library -->
	<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>

	<!-- Popper JS -->
	<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>

	<!-- Latest compiled JavaScript -->
	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
</head>
<body>
	<div class="container">
		<div class="row">
			<div class="col-lg-12 col-md-12 col-xs-12">
				<div class="panel-primary">
					<div class="panel-heading" style="margin-top: 20px">
						<h3 style="color: red; text-align: center;">QUẢN LÝ THƯ VIỆN</h3> 
					</div>
					<div class="panel-body">
						<table class="table table-bordered">
							<thead>
								<tr>
									<th width="30px">STT</th>
									<th>Tilte </th>
									<th>ISBN</th>
									<th>PUB YEAR</th>
									<th>Available</th>
								</tr>
							</thead>
							<tbody>
								<?php 
									$sql = 'select * from book';
									$bookList = executeResult($sql);
									$count = 1;
									foreach ($bookList as $item) {
										
										echo '<tr>
											 	<td>'.($count++).'</td>
											 	<td>'.$item['tilte'].'</td>
											 	<td>'.$item['isbn'].'</td>
											 	<td>'.$item['pub_year'].'</td>
											 	<td>'.$item['available'].'</td>								 	
											 </tr>';
									}
								 ?>
							</tbody>
						</table>
						
					</div>
				</div>
				
			</div>
			
		</div>

		

		
	</div>
	
</body>
</html>




<?php 
	require_once('dbhelper.php');


	
 ?>

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>Library</title>
	<!-- Latest compiled and minified CSS -->
	<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">

	<!-- jQuery library -->
	<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>

	<!-- Popper JS -->
	<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>

	<!-- Latest compiled JavaScript -->
	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
</head>
<body>
	<div class="container">
		<div class="row">
			<div class="col-lg-12 col-md-12 col-xs-12">
				<form method="post">
					<input type="text" name="search" style="width: 500px;">
					<button class="btn btn-success">TÌM KIẾM</button>
				</form>
				
				<div class="panel-primary">
					<div class="panel-heading" style="margin-top: 20px">
						<h3 style="color: red; text-align: center;">TÌM KIẾM SÁCH</h3> 
					</div>
					<div class="panel-body">
						<table class="table table-bordered">
							<thead>
								<tr>
									<th width="30px">STT</th>
									<th>Tilte </th>
									<th>ISBN</th>
									<th>PUB YEAR</th>
									<th>Available</th>
								</tr>
							</thead>
							<tbody>
								<?php 
									$search = $POST['search'];


									$sql = 'select * from book';
									$bookList = executeResult($sql);
									$count = 1;
									foreach ($bookList as $item) {
										if ($item['tilte'] == $search) {
											echo '<tr>
											 	<td>'.($count++).'</td>
											 	<td>'.$item['tilte'].'</td>
											 	<td>'.$item['isbn'].'</td>
											 	<td>'.$item['pub_year'].'</td>
											 	<td>'.$item['available'].'</td>								 	
											 </tr>';
										}
										
										
									}
								 ?>
							</tbody>
						</table>
						
					</div>
				</div>
				
			</div>
			
		</div>

		

		
	</div>
	
</body>
</html>




Bùi Văn Mạnh [T2008A]
Bùi Văn Mạnh

2021-06-30 09:12:11



<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateBooklistTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('booklist', function (Blueprint $table) {
            $table->bigIncrements('bookid');
            $table->bigInteger('authorid');
            $table->string('title', 55);
            $table->string('ISBN', 25);
            $table->unsignedSmallInteger('pub_year');
            $table->tinyInteger('available');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('booklist');
    }
}



nguyễn Sử [T2008A]
nguyễn Sử

2021-06-30 09:10:52



<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateExamTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('exam', function (Blueprint $table) {
            $table->id('bookid');
            $table->int('authorid');
            $table->string('title', 55);
            $table->string('ISBN', 25);
            $table->smallint('pub_year', 6);
            $table->tinyint('avilble', 4);
            
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('exam');
    }
}



nguyễn Sử [T2008A]
nguyễn Sử

2021-06-30 09:10:34



<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;

class LibrarySeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        for ($i=1; $i <= 5; $i++) { 
            DB::table('exam')->insert([
                'authorid' => $i,
                'title' => 'zzzzzz' . $i,
                'ISBN' => '1' . $i,
                'pub_year' => '1'.$i,
                'available' => $i + 10
            ]);
        }
        
    }
}



nguyễn Sử [T2008A]
nguyễn Sử

2021-06-30 09:10:04


index.blade.php
<!doctype html>
<html lang="en">
  <head>
    <title>Exam</title>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="{{ asset('css/library.css') }}">
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
  </head>
  <body>
    <div class="container">
        <h1>Exam</h1>
        <form method="get">
            <div class="form-group">
              <input type="text" class="form-control" name="search"  placeholder="Searching for title...">
            </div>
        </form>
        <table class="table table-bordered">
            <thead>
                <tr>
                    <th>No</th>
                    <th>Title</th>
                    <th>ISBN</th>
                    <th>Publish Year</th>
                    <th>Available</th>
                    <th></th>
                    <th></th>

                </tr>
            </thead>
            <tbody>
                @foreach ($bookList as $book)
                    <tr>
                        <td>{{$index++}}</td>
                        <td>{{$book -> title}}</td>
                        <td>{{$book -> ISBN}}</td>
                        <td>{{$book -> pub_year}}</td>
                        <td>{{$book -> available}}</td>
                    </tr>
                @endforeach
            </tbody>
        </table>
    </div>  
  </body>
</html>



vuong huu phu [T2008A]
vuong huu phu

2021-06-30 09:09:14



<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreatLibraryTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
         Schema::create('library', function (Blueprint $table) {
            $table->id();
            $table->integer('authorid');
            $table->string('title',25);
            $table->string('ISBN');
            $table->integer('pud_year');
            $table->integer('available');
            });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        //
    }
}



<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;
use DB;
class lybrarySeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
         for($i =1 ; $i < 20;$i ++){
        DB::table('library')->insert([
            'authorid'   => $i,
            'title'   => 'cuon sach '.$i,
            'ISBN'   => 'ABC',
            'pud_year'   => 2021 ,
            'available'   => 123
        ]);
       } 
    }
}



<?php
use Illuminate\Support\Facades\Route;
		Route::get('/library/book','App\Http\Controllers\library@quon_sach')->name('library_show');
		



<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use DB;
class library extends Controller
{
     public function quon_sach (Request $request) {
        $s = $request->s;
     if (isset($s)) {
            $list_library = DB::table('library')->where('library.title', 'like', '%'.$s.'%')->paginate(10);
        }else{
    $list_library= DB::table('library')->paginate(10);
    }
            return view('library')->with([
                'list_library'  => $list_library,
                'count' => 1
            ]);  
    }
  
}




<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>thu vien</title>
    <!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">

<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

<!-- Popper JS -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>

<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js"></script>
</head>
<body>
    <div class="container">
        <form method="get">
            <input type="text" name="s" class="form-control" style="width: 160px; margin-left: 10px;">
        </form>
        <table class="table table-bordered">
            <thead>
              <tr>
                <th>STT</th>
                <th>authorid</th>
                <th>Tên sach</th>
                <th>ISBN</th>
                <th>YEAR</th>
                <th>available</th>
              </tr>
            </thead>
            <tbody>
             @foreach ($list_library as $library)
            <tr>
                <td>{{$count++}}</td>
             <td>{{$library -> authorid}}</td>   
             <td>{{$library -> title}}</td>
             <td>{{$library -> ISBN}}</td>
             <td>{{$library -> pud_year}}</td>
             <td>{{$library -> available}}</td>
              </tr>
             @endforeach
              
            </tbody>
          </table>
          <div class="d-flex justify-content-center">
    {{ $list_library->links() }}
</div>
                
        <br>
        
      </div>
    



Đỗ Mạc Nam [T2008A]
Đỗ Mạc Nam

2021-06-30 09:08:31



<!doctype html>
<html lang="en">
  <head>
    <title>Book List</title>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- Bootstrap CSS -->
    <style>
        body{
            background-color: red !important;
        }
        h1{
            text-align: center;
            color: blue;
        }
        input{
            width: 180px !important;
        }
    </style>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
  </head>
  <body>
    <div class="container">
        <h1>Book list</h1>
        <form method="get">
            <div class="form-group">
              <input type="text" class="form-control" name="search">
            </div>
        </form>
        <table class="table table-bordered">
            <thead>
                <tr>
                    <th>No</th>
                    <th>Title</th>
                    <th>ISBN</th>
                    <th>Publish Year</th>
                    <th>Available</th>
                </tr>
            </thead>
            <tbody>
                @foreach ($bookList as $item)
                    <tr>
                        <td>{{$index++}}</td>
                        <td>{{$item -> title}}</td>
                        <td>{{$item -> ISBN}}</td>
                        <td>{{$item -> pub_year}}</td>
                        <td>{{$item -> available}}</td>
                    </tr>
                @endforeach
            </tbody>
        </table>
    </div>  
  </body>
</html>



Đỗ Mạc Nam [T2008A]
Đỗ Mạc Nam

2021-06-30 09:05:14



<?php

namespace App\Http\Controllers\Library;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class LibraryController extends Controller
{
    public function showBook(Request $request)
    {
        $s = $request->s;
        $bookList = DB::table('library');
        if(isset($s) && $s > 0){
            $bookList = $bookList->where('library.title','like','%'.$s.'%');
        }
        $bookList = $bookList->get();
        return view('library.index')->with([
            'bookList' => $bookList,
            'index' => 1
        ]);
    }
}



Đỗ Mạc Nam [T2008A]
Đỗ Mạc Nam

2021-06-30 09:05:02



Route::get('/library/index',[\App\Http\Controllers\Library\LibraryController::class,"showBook"]);



Đăng nhập để làm bài kiểm tra

Chưa có kết quả nào trước đó