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
Tags:
Phản hồi từ học viên
5
(Dựa trên đánh giá ngày hôm nay)
![Vũ Đình Khôi [community,T2008A]](https://www.gravatar.com/avatar/522a3ab049e7409705e97b96dbbc327b.jpg?s=80&d=mm&r=g)
Vũ Đình Khôi
2021-06-30 09:26:03
lý thuyết
![Đức Sơn [T2008A]](https://www.gravatar.com/avatar/d2b971b7bc54e4a9689c3e2240f27949.jpg?s=80&d=mm&r=g)
Đức Sơn
2021-06-30 09:25:55
<!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>
![Trần Thị Khánh Huyền [T2008A]](https://www.gravatar.com/avatar/554e115833778e4294a01aebe228f3d6.jpg?s=80&d=mm&r=g)
Trần Thị Khánh Huyền
2021-06-30 09:25:28
#bookSeeder.php
<?php
use Illuminate\Database\Seeder;
class bookSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
//
for ($i=0; $i < 50; $i++) {
# code...
DB::table('book')->insert([
'authorid' => $i*10000,
'title' => 'book '.($i+1),
'ISBN' => Str::random(100),
'pub_year' => '2020-01-07'
'available' => $i*10,
]);
}
}
}
![hainguyen [T2008A]](https://www.gravatar.com/avatar/32855ce6db55d60134d830aee06b41e5.jpg?s=80&d=mm&r=g)
hainguyen
2021-06-30 09:25:22
#Booklist.php
<?php
namespace App\Http\Controllers\Book;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class Booklist extends Controller
{
public function showBook(Request $request)
{
$s = $request->s;
$bookList = DB::table('booklist');
if(isset($s) && $s > 0){
$bookList = $bookList->where('booklist.title','like','%'.$s.'%');
}
$bookList = $bookList->get();
return view('booklist.index')->with([
'bookList' => $bookList,
'index' => 1
]);
}
}
#index.blade.php
<!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>
#library.php
<?php
use Illuminate\Support\Facades\Route;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('/library/index', [\App\Http\Controllers\Book\Booklist::class,"showBook"]);
#2021_06_30_082502_create_booklist_table.php
<?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');
}
}
#DatabaseSeeder.php
<?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 <= 10; $i++) {
DB::table('booklist')->insert([
'authorid' => $i,
'title' => ' ' . $i,
'ISBN' => '' . $i,
'pub_year' => ''.$i,
'available' => $i + 20
]);
}
}
}
![Do Trung Duc [T2008A]](https://www.gravatar.com/avatar/2973ac07124f066b4605c535e8d39a99.jpg?s=80&d=mm&r=g)
Do Trung Duc
2021-06-30 09:23:09
<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
use App\Models\LibraryBook;
class LibraryBookSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
for( $i = 1; $i <=35 ; $i++){
LibraryBook::insert([
"authorid" => 1,
'title' => "Sach thu ".$i,
'ISBN' => "Sach hay",
'pub_year' => 2021,
'available' => 10,
]);
}
}
}
![Nguyên Phấn Đông [T2008A]](https://www.gravatar.com/avatar/c9c4f8f79ce35b9224637b6cc5fbe5c4.jpg?s=80&d=mm&r=g)
Nguyên Phấn Đông
2021-06-30 09:23:08
#config.php
<?php
define('HOST', 'localhost');
define('USERNAME', 'root');
define('PASSWORD', '');
define('DATABASE', 'thuvien');
// create table book (
// bookid int primary key auto_increment,
// authorid int,
// title varchar(55) not null,
// thumbnial varchar(500),
// ISBN varchar(22) ,
// pub_year SMALLINT(6),
// available tinyint(4)
// )
#dbhelper.php
<?php
require_once('config.php');
function execute($sql){
$conn = mysqli_connect(HOST,USERNAME,PASSWORD,DATABASE);
mysqli_set_charset($conn,'utf8');
mysqli_query($conn, $sql);
mysqli_close($conn);
}
function executeResult($sql){
$conn = mysqli_connect(HOST,USERNAME,PASSWORD,DATABASE);
mysqli_set_charset($conn,'utf8');
$resultset = mysqli_query($conn, $sql);
$data = [];
while( ($row = mysqli_fetch_array($resultset,1)) !=null ){
$data[] = $row;
}
mysqli_close($conn);
return $data;
}
#index.php
<?php
require_once("dbhelper.php");
$sql = "select * from book";
$data = executeResult($sql);
?>
<!DOCTYPE html>
<html>
<head>
<title>Quản Lý Thư Viện</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.4.0/font/bootstrap-icons.css">
<!-- include summernote css/js -->
<link href="https://cdn.jsdelivr.net/npm/summernote@0.8.18/dist/summernote.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/summernote@0.8.18/dist/summernote.min.js"></script>
</head>
<body>
<div class="container">
<div class="card">
<div class="card-header bg-info text-light text-uppercase">
Quản Lý Thư Viện
</div>
</div>
<input type="text" class="form-control" style="margin-top: 10px; margin-bottom: 10px; float: right;" placeholder="Tìm kiếm ..." onkeyup="funcSeaching(this)">
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>STT</th>
<th>Hình Ảnh</th>
<th>Tên Sách</th>
<th>Năm</th>
<th>Còn thư viện</th>
<th>ID tác giả</th>
</tr>
</thead>
<tbody>
<?php
$count = 0;
foreach ($data as $book) {
if($book['available'] == 0) {$ab = "còn";}
else {$ab = "hết";}
echo '<tr>
<td>'.++$count.'</td>
<td><img src ='.$book['thumbnial'].' style = "width : 120px"/></td>
<td>'.$book['ISBN'].'<p>'.$book['title'].'<p>'.'</td>
<td>'.$book['pub_year'].'</td>
<td>'.$ab.'</td>
<td>'.$book['authorid'].'</td>
</tr>';
}
?>
</tbody>
</table>
</div>
</body>
</html>
![Trần Thị Khánh Huyền [T2008A]](https://www.gravatar.com/avatar/554e115833778e4294a01aebe228f3d6.jpg?s=80&d=mm&r=g)
Trần Thị Khánh Huyền
2021-06-30 09:22:49
#create_book_table.php
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreatebookTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('book', function (Blueprint $table) {
$table->increments('id');
$table->integer('authorid');
$table->string('title', 55);
$table->string('IBSN', 25);
$table->integer('pub_year');
$table->integer('available');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('book');
}
}
![Do Trung Duc [T2008A]](https://www.gravatar.com/avatar/2973ac07124f066b4605c535e8d39a99.jpg?s=80&d=mm&r=g)
Do Trung Duc
2021-06-30 09:22:46
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class LibraryBook extends Model
{
use HasFactory;
protected $table = "booklibrary";
protected $fillable = [
"authorid",
"title",
"ISBN",
"pub_year",
"available",
];
}
![Do Trung Duc [T2008A]](https://www.gravatar.com/avatar/2973ac07124f066b4605c535e8d39a99.jpg?s=80&d=mm&r=g)
Do Trung Duc
2021-06-30 09:22:09
body {
text-align: center;
}
#total {
margin-top: 50px;
}
#title {
font-weight: bold;
font-size: 20px;
}
![Bùi Văn Mạnh [T2008A]](https://www.gravatar.com/avatar/17e9c94870c94e61c9203ee31dccf01c.jpg?s=80&d=mm&r=g)
Bùi Văn Mạnh
2021-06-30 09:22:08
<!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>