By GokiSoft.com|
20:36 05/01/2024|
Học PHP
Hiển thị ngẫu nhiên N quyển sách bằng PHP - Quản lý sách bằng PHP
Sinh ngẫu nhiên một mảng gồm N quyển sách
- N cũng là số ngẫu nhiên đc sinh ra từ PHP
- Mỗi quyển sách gồm các thuộc tính tên sách, tác giả, giá bán, nhà xuất bản => mỗi giá trị cũng đc sinh ngẫu nhiên.
Hiển thị dữ liệu ra bảng
Chú ý: Giá trị sinh ngẫu nhiên như sau :
Quyển sách 1:
- Tên: quyển sách 1
- Tác giả: tác giả 1
- Giá 100
- Nhà xuất bản: nhà xuất bản 1
(thay số 1 thành các số bất kỳ từ 1-100)
Tags:
Phản hồi từ học viên
5
(Dựa trên đánh giá ngày hôm nay)
Nguyễn đình quân
2020-09-16 06:33:30
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.0/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.0/js/bootstrap.min.js"></script>
<title>Hoang Duy Minh</title>
</head>
<body>
<?php
$rd = rand(1,100);
$bookList = [];
for($i = 0; $i < $rd; $i++){
$book = [
'bookName' => 'Ten Sach ' .($i + 1),
'authorName' => 'Tac Gia' .($i + 1),
'price' => rand(1,100),
'NXB' => 'Nha xuat ban' .($i+1)
];
$bookList[] = $book;
}
?>
<div class="container">
<table class = "table">
<tr>
<th>Ten Sach</th>
<th>Ten Tac Gia</th>
<th>Gia </th>
<th>Producer</th>
</tr>
</table>
</div>
<?php
for ($i=0; $i < $rd; $i++) {
$book1 = $bookList[$i];
echo '<tr>'.
'<th>'.($book1['bookName']).'</th>'.'<br/>'.
'<th>'.($book1['authorName']).'</th>'.'<br/>'.
'<th>'.($book1['price']).'</th>'.'</br>'.
'<th>'.($book1['NXB']).'</th>'.'</br>'.
'</tr>';
}
?>
</body>
</html>
hoangduyminh
2020-06-14 23:20:48
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.0/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.0/js/bootstrap.min.js"></script>
<title>Hoang Duy Minh</title>
</head>
<body>
<?php
$rd = rand(1,100);
$bookList = [];
for($i = 0; $i < $rd; $i++){
$book = [
'bookName' => 'Ten Sach ' .($i + 1),
'authorName' => 'Tac Gia' .($i + 1),
'price' => rand(1,100),
'NXB' => 'Nha xuat ban' .($i+1)
];
$bookList[] = $book;
}
?>
<div class="container">
<table class = "table">
<tr>
<th>Ten Sach</th>
<th>Ten Tac Gia</th>
<th>Gia </th>
<th>Producer</th>
</tr>
</table>
</div>
<?php
for ($i=0; $i < $rd; $i++) {
$book1 = $bookList[$i];
echo '<tr>'.
'<th>'.($book1['bookName']).'</th>'.'<br/>'.
'<th>'.($book1['authorName']).'</th>'.'<br/>'.
'<th>'.($book1['price']).'</th>'.'</br>'.
'<th>'.($book1['NXB']).'</th>'.'</br>'.
'</tr>';
}
?>
</body>
</html>
Phạm Ngọc Minh
2020-06-14 16:10:35
<!DOCTYPE html>
<html>
<head>
<title>QLS</title>
</head>
<body>
<?php
$a = rand(1,100);
$bookList = [];
for ($i=0; $i < $a; $i++) {
$book = [
'Tensach' => 'quyển sách '.($i+1),
'TC' => 'tác giả '.($i+1),
'GIA' => rand(100,10000),
'NXB' => 'nhà xuất bản '.($i+1)
];
$bookList[] = $book;
}
?>
<div class="a">
<table class="b">
<thead>
<style>
table,th,td {
border: 1px solid black;
border-collapse: collapse;
}
th,td {
padding: 15px;
}
</style>
<tr>
<th>Tên Sách</th>
<th>Tác Giả</th>
<th>Giá</th>
<th>Nhà Xuất Bản</th>
</tr>
</thead>
<tbody>
<?php
for ($i=0; $i < $a; $i++) {
$book1 = $bookList[$i];
echo '<tr>'.
'<td>'.($book1['Tensach']).'</td>'.
'<td>'.($book1['TC']).'</td>'.
'<td>'.($book1['GIA']).'</td>'.
'<td>'.($book1['NXB']).'</td>'.
'</tr>';
}
?>
</tbody>
</table>
</div>
</body>
</html>
Luong Dinh Dai
2020-06-14 15:36:27
<?php
$random = random_int(1,100);
$bookList = [];
for ($i=0; $i < $random; $i++) {
$book = [
'bookName' => 'Quyển sách '.($i+1),
'authorName' => 'Tác giả '.($i+1),
'price' => random_int(1,100),
'NXB' => 'Nhà xuất bản '.($i+1)
];
$bookList[] = $book;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<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.0/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.0/js/bootstrap.min.js"></script>
<title>Document</title>
</head>
<body>
<div class="container">
<table class="table-bordered">
<thead>
<tr>
<th>Tên</th>
<th>Tác giả</th>
<th>Giá</th>
<th>Nhà xuất bản</th>
</tr>
</thead>
<tbody>
<?php
for ($i=0; $i < $random; $i++) {
$book1 = $bookList[$i];
echo '<tr>'.
'<td>'.($book1['bookName']).'</td>'.
'<td>'.($book1['authorName']).'</td>'.
'<td>'.($book1['price']).'</td>'.
'<td>'.($book1['NXB']).'</td>'.
'</tr>';
}
?>
</tbody>
</table>
</div>
</body>
</html>
Trần Anh Quân
2020-06-14 12:26:41
<!DOCTYPE html>
<html>
<head>
<title>Hiển thị N quyển sách ngẫu nhiên</title>
</head>
<body>
<?php
$random = rand(1,100);
$bookList = [];
for ($i=0; $i < $random; $i++) {
$book = [
'bookName' => 'Quyển sách '.($i+1),
'authorName' => 'Tác giả '.($i+1),
'price' => rand(100,1000),
'NXB' => 'Nhà xuất bản '.($i+1)
];
$bookList[] = $book;
}
?>
<table border="1">
<thead>
<tr>
<th>Tên sách</th>
<th>Tác Giả</th>
<th>Giá</th>
<th>Nhà xuất bản</th>
</tr>
</thead>
<tbody>
<?php
for ($i=0; $i < $random; $i++) {
$book1 = $bookList[$i];
echo '<tr>'.
'<td>'.($book1['bookName']).'</td>'.
'<td>'.($book1['authorName']).'</td>'.
'<td>'.($book1['price']).'</td>'.
'<td>'.($book1['NXB']).'</td>'.
'</tr>';
}
?>
</tbody>
</table>
</body>
</html>
thienphu
2020-06-14 01:45:39
#ViewBook2.php
<?php
$random = random_int(1,100);
$bookList = [];
for ($i=0; $i < $random; $i++) {
$book = [
'bookName' => 'Quyển sách '.($i+1),
'authorName' => 'Tác giả '.($i+1),
'price' => random_int(1,100),
'NXB' => 'Nhà xuất bản '.($i+1)
];
$bookList[] = $book;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<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.0/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.0/js/bootstrap.min.js"></script>
<title>Document</title>
</head>
<body>
<div class="container">
<table class="table-bordered">
<thead>
<tr>
<th>Tên</th>
<th>Tác giả</th>
<th>Giá</th>
<th>Nhà xuất bản</th>
</tr>
</thead>
<tbody>
<?php
for ($i=0; $i < $random; $i++) {
$book1 = $bookList[$i];
echo '<tr>'.
'<td>'.($book1['bookName']).'</td>'.
'<td>'.($book1['authorName']).'</td>'.
'<td>'.($book1['price']).'</td>'.
'<td>'.($book1['NXB']).'</td>'.
'</tr>';
}
?>
</tbody>
</table>
</div>
</body>
</html>
Minh Nghia
2020-06-13 10:00:47
<?php
$ran = mt_rand(1,100);
$bookList = [];
for ($i=0; $i < $ran; $i++) {
$book = [
'BookName' => 'Quyen Sach'.mt_rand(1,100),
'Author' => 'Tac Gia'.mt_rand(1,100),
'Price' => 'Gia Ban'.mt_rand(1,100),
'Producer' => 'Nha San Xuat'.mt_rand(1,100)
];
$bookList[] = $book;
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Book Management</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.0/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.0/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<table class="table table-dark table-striped" >
<thead>
<tr>
<th>Book Name</th>
<th>Author</th>
<th>Price</th>
<th>Producer</th>
</tr>
</thead>
<tbody>
<?php
for ($i=0; $i < $ran; $i++) {
$book1 = $bookList[$i];
echo'<tr>'.
'<td>'.($book1['BookName']).'</td>'.
'<td>'.($book1['Author']).'</td>'.
'<td>'.($book1['Price']).'</td>'.
'<td>'.($book1['Producer']).'</td>'
.'</tr>';
}
?>
</tbody>
</table>
</div>
</body>
</html>
lê văn phương
2020-06-13 10:00:09
<?php
$n= rand(1,100);
echo "$n..".$n;
$tr ='';
for ($i=0; $i < $n; $i++) {
$tensach = 'toi_yeu_VN'.$i;
$tacgia = 'Phuong'.$i;
$giaban = '10000'.$i;
$ngaysanxuat ='1-1-1111'.$i;
$tr .= '<tr>' .
'<td>' .$tensach. '</td>' .
'<td>' . $tacgia . '</td>' .
' <td>' . $giaban. '</td>' .
'<td>' . $ngaysanxuat . '</td>' .
'</tr>';
}
// if (!empty($_Get)) {
// if (isset($_Get['tensach'])) {
// $tensach = $_Get['tensach'];
// }
// if (isset($_Get['tacgia'])) {
// $tacgia = $_Get['tacgia'];
// }
// if (isset($_Get['giaban'])) {
// $giaban = $_Get['giaban'];
// }
// if (isset($_Get['ngaysanxuat'])) {
// $ngaysanxuat = $_Get['ngaysanxuat'];
// }
// }
?>
<!DOCTYPE html>
<html>
<head>
<title>Quản lý sách</title>
<!-- CSS only -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
<!-- JS, Popper.js, and jQuery -->
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></script>
</head>
<body>
<div class="contener">
<div class="top">
<table border="1px">
<tr>
<th>Tên sách</th>
<th>Tác giả</th>
<th>Giá bán</th>
<th>Ngày sản xuất</th>
</tr>
<?= $tr?>
</table>
</div>
</div>
</body>
</html>
NguyenHuuThanh
2020-06-12 15:20:06
<!DOCTYPE html>
<html>
<head>
<title>Random number Array</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">
</head>
<body>
<?php
$random = mt_rand(1,100);
$booklist = [];
for ($i = 0 ; $i < $random ; $i++)
{
$book = [
'bookName' => 'Quyen Sach'.mt_rand(1,100),
'authorName' => 'Tac gia'.mt_rand(1,100),
'price' => mt_rand(1,100),
'NXB' => 'NXB'.mt_rand(1,100)
];
$booklist[] = $book ;
}
?>
<div class = "container">
<table class = "table - bordered">
<thead>
<tr>
<th> Ten </th>
<th> Tac gia </th>
<th> Gia </th>
<th> Nha xuat ban </th>
</tr>
</thead>
<tbody>
<?php
for ($i = 0 ; $i < $random ; $i++)
{
$book1 = $booklist[$i];
echo '<tr>'.
'<td>'.($book1['bookName']).'</td>'.
'<td>'.($book1['authorName']).'</td>'.
'<td>'.($book1['price']).'</td>'.
'<td>'.($book1['NXB']).'</td>'
.'</tr>';
}
?>
</tbody>
</table>
</div>
</body>
</html>
Trần Mạnh Dũng
2020-06-12 13:49:45
#baitap1.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<?php
$random = mt_rand(1,100);
$bookList = [];
for ($i=0; $i < $random; $i++) {
$book = [
'bookName' => 'Quyển sách '.($i+1),
'authorName' => 'Tác giả '.($i+1),
'price' => mt_rand(1,100),
'NXB' => 'Nhà xuất bản '.($i+1)
];
$bookList[] = $book;
}
?>
<div class="container">
<table class="table-bordered">
<thead>
<tr>
<th>Tên</th>
<th>Tác giả</th>
<th>Giá</th>
<th>Nhà xuất bản</th>
</tr>
</thead>
<tbody>
<?php
for ($i=0; $i < $random; $i++) {
$book1 = $bookList[$i];
echo '<tr>'.
'<td>'.($book1['bookName']).'</td>'.
'<td>'.($book1['authorName']).'</td>'.
'<td>'.($book1['price']).'</td>'.
'<td>'.($book1['NXB']).'</td>'.
'</tr>';
}
?>
</tbody>
</table>
</div>
</body>
</html>