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)
![Võ Như Việt [C2010L]](https://www.gravatar.com/avatar/fb93c99beb23339eb21f4d4ffe8981af.jpg?s=80&d=mm&r=g)
Võ Như Việt
2021-05-07 08:06:17
<!DOCTYPE html>
<html>
<head>
<title>Hiển thị ngẫu nhiên N quyển sách bằng PHP - Quản lý sách bằng PHP</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://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head>
<body>
<?php
$N = rand(1,100);
$QuyenSach= [];
for ($i=0; $i <= $N ; $i++)
{
$QuyenSach[] =[
'title' => 'quyển sách'.$i,
'authorname' => 'tác giả'.$i,
'price' => rand(1,100),
'nsx' => 'nhà xuất bản'.$i,
];
}
?>
<div class="container">
<table class="table table-bordered">
<thead>
<tr>
<th>No</th>
<th>Title</th>
<th>Author Name</th>
<th>Price</th>
<th>NSX</th>
</tr>
</thead>
<tbody>
<?php
$count = 0;
foreach ($QuyenSach as $item) {
echo '<tr>
<td>'.(++$count).'</td>
<td>'.$item['title'].'</td>
<td>'.$item['authorname'].''.'</td>
<td>'.$item['price'].'</td>
<td>'.$item['nsx'].'</td>
</tr>';
}
?>
</tbody>
</table>
</div>
</body>
</html>
![hieuvm0512 [community,C2010L]](https://www.gravatar.com/avatar/0cacbf21fed14b987a433597d2edc14f.jpg?s=80&d=mm&r=g)
hieuvm0512
2021-05-06 17:12:39
<!DOCTYPE html>
<html>
<head>
<title>Sinh so ngau nhien</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>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script type="text/javascript" charset="utf8" src="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.3.3/jstree.min.js"></script>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
<script src="main.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.4.0/font/bootstrap-icons.css">
</head>
<body>
<div class="container">
<table class="table table-bordered">
<thead>
<tr>
<th>No</th>
<th>Book</th>
<th>Author Name</th>
<th>Price</th>
<th>Publisher no</th>
</tr>
</thead>
<tbody>
<?php
$N = rand(1,100);
echo "So Luong Sach ", $N;
for ($i=1; $i <=$N ; $i++) {
$item = [
'No'=>rand(1,100),
'Book'=>rand(1,100),
'Author'=>rand(1,100),
'Price'=>rand(1,100),
'Publisher'=>rand(1,100)
];
echo '<tr>
<td>'.$item['No'].'</td>
<td>'.$item['Book'].'</td>
<td>'.$item['Author'].'</td>
<td>'.$item['Price'].'</td>
<td>'.$item['Publisher'].'</td>
</tr>';
}
?>
</tbody>
</table>
</div>
</body>
</html>
![Đỗ Phan Hà [community,C2010L]](https://www.gravatar.com/avatar/644556c9d81d43016df661abe38dff3a.jpg?s=80&d=mm&r=g)
Đỗ Phan Hà
2021-05-06 13:58:51
<!DOCTYPE html>
<html>
<head>
<title>Thuvien</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">
</head>
<body>
<?php
$book = [];
$lenght = rand(1,100);
for ($i=0; $i < $lenght; $i++) {
$booklist[] = [
'title' => "Quyen sach $i" ,
'authorname' => "Tac gia $i" ,
'price' => rand(1000,10000),
'nsx' => "Nha Xuat Ban $i"
];
}
?>
<div class="container">
<table class="table table-bordered">
<thead>
<tr>
<th>No</th>
<th>Title</th>
<th>Author Name</th>
<th>NSX</th>
<th>Price</th>
</tr>
</thead>
<tbody>
<?php
$count = 0;
foreach ($booklist as $item) {
echo '<tr>
<td>'.(++$count).'</td>
<td>'.$item['title'].'</td>
<td>'.$item['authorname'].'</td>
<td>'.$item['nsx'].'</td>
<td>'.$item['price'].'</td>
</tr>';
}
?>
</tbody>
</table>
</body>
</html>
![Lã Đức Anh [community,C2010L]](https://www.gravatar.com/avatar/6ba958fe697787cee13bc898c4c1f7cf.jpg?s=80&d=mm&r=g)
Lã Đức Anh
2021-05-06 13:49:46
<?php
$array = [];
$n = rand(1,100);
for ($i=0; $i < $n ; $i++) {
$array ['Book'.$i] ['Name'] = 'Quyển Sách'.$i;
$array ['Book'.$i] ['Author'] = 'Tác Giả'.$i;
$array ['Book'.$i] ['Price'] = $i.'00';
$array ['Book'.$i] ['Publishing Company'] = 'NXB'.$i;
}
foreach ($array as $key => $value) {
echo $key . ':' . '<br>';
foreach ($value as $key1 => $value1) {
echo '  -' . $key1 . ' : ' . $value1;
echo '<br>';
}
echo '<br>';
}
?>
![Le Duc Viet [community,C2010L]](https://www.gravatar.com/avatar/3b533532c7ace3144eccd4cbb3436d9b.jpg?s=80&d=mm&r=g)
Le Duc Viet
2021-05-06 13:44:45
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<?php
$book = [];
$lenght = rand(1,1000);
for ($i=0; $i < $lenght; $i++) {
$book[] = [
'Ten' => "Quyen sach $i" ,
'Tac Gia' => "Tac gia $i" ,
'Gia' => 100,
'NXB' => "Nha Xuat Ban $i"
];
}
var_dump($book);
?>
</body>
</html>
![Phạm Ngọc Đại [community,C2010G]](https://www.gravatar.com/avatar/a2d762c32047edba0ef5bd2049993b20.jpg?s=80&d=mm&r=g)
Phạm Ngọc Đại
2021-04-23 03:34:02
<!DOCTYPE html>
<html>
<head>
<title>STUDENT 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.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>
<style type="text/css">
table tr td {
border: 1px solid black;
margin: 5px;
padding: 5px;
}
</style>
</head>
<body>
<?php
$book = [];
$n = rand(1,100);
for ($i=1; $i <= $n ; $i++) {
$book1 = [
'Name' => 'quyen sach '.$i,
'Author' => 'tac gia '.$i,
'Price' => rand(1,100),
'Publish' => 'NXB '.$i,
];
$book[] = $book1;
}
// echo $book[0]['Name'];
?>
<table>
<?php
foreach ($book as $key) {
echo '<tr>'.
'<td>'.$key['Name'].'<td>'.
'<td>'.$key['Author'].'<td>'.
'<td>'.$key['Price'].'<td>'.
'<td>'.$key['Publish'].'<td>'.
'<tr>';
}
?>
</table>
</body>
</html>
![PHẠM VĂN LIÊM [C2010G]](https://www.gravatar.com/avatar/dd86ba4e56b73bc1514e889b2ac18c6d.jpg?s=80&d=mm&r=g)
PHẠM VĂN LIÊM
2021-04-23 03:28:17
<!DOCTYPE html>
<html>
<head>
<title>Quản Lí Sách</title>
<meta charset="utf-8">
</head>
<body>
<?php
$array = [];
$n = rand(1,100);
for($i=1;$i<$n;$i++) {
$array['Book ' . $i]['Name'] = 'quyển sách ' . $i;
$array['Book ' . $i]['Auther'] = 'tác giả ' . $i;
$array['Book ' . $i]['price'] = $i . '$';
$array['Book ' . $i]['Publishing Company'] = 'Nhà xuất bản' . $i;
}
foreach ($array as $key => $value) {
echo $key . '<br>';
foreach($value as $key1 => $value) {
echo '' . $key1 . ': ' .$value;
echo '<br>';
}
echo '<br>';
}
?>
</body>
</html>
![Nguyễn Tiến Đạt [T2008A]](https://www.gravatar.com/avatar/b5819cd0adc95c727c7ad0c2bcf6098b.jpg?s=80&d=mm&r=g)
Nguyễn Tiến Đạt
2021-04-16 08:25:50
<?php
$array=[];
$n = rand(0,100);
for ($i=1; $i < $n ; $i++) {
$array['Quyển sách ' . $i]['Tên'] = 'quyển sách ' .$i;
$array['Quyển sách ' . $i]['Tác giả'] = 'tác giả ' .$i;
$array['Quyển sách ' . $i]['Giá'] = $i . '00';
$array['Quyển sách ' . $i]['Nhà xuất bản'] = 'nhà xuất bản ' .$i;
}
foreach ($array as $key => $value) {
echo $key . ':' . '<br>';
foreach($value as $key1 => $value1){
echo '  -' . $key1 . ': ' . $value1;
echo '<br>';
}
echo '<br>';
}
![Nguyễn Hoàng Hiệp [community,C2010G]](https://www.gravatar.com/avatar/8838f54079683f30f23ba7b170396c08.jpg?s=80&d=mm&r=g)
Nguyễn Hoàng Hiệp
2021-04-16 04:24:06
<!DOCTYPE html>
<html>
<head>
<title>hien thi nguyen nhien so quyen sach</title>
</head>
<style type="text/css">
table th { border: 1px solid black }
</style>
<body>
<?php
$sc=rand(1,100);
$sach=[];
for ($i=0; $i<$sc;$i++) {
$sach1=[
$tensach= $sc,
$tacgia =$sc,
$giaban= rand(1,1000),
$NXB= $sc,
];
$sach=$sach1;}
?>
<table cellspacing="0" >
<thead>
<tr>
<th>Ten Sach</th>
<th>Ten Tac Gia</th>
<th>Gia </th>
<th>NXB</th>
</tr>
</thead>
<tbody>
<tr>
<th><?=$tensach?></th>
<th><?=$tacgia?></th>
<th><?=$giaban?></th>
<th><?=$NXB?></th>
</tr>
</tbody>
</table>
</body>
</html>
![Nguyen Trung Kien [community,C2010G]](https://www.gravatar.com/avatar/598b6cbd59c38ba0404dfa2129befa0a.jpg?s=80&d=mm&r=g)
Nguyen Trung Kien
2021-04-16 04:19:02
<!DOCTYPE html>
<html>
<head>
<title>Hiển thị ngẫu nhiên N quyển sách bằng PHP </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">
</head>
<body>
<?php
$n = rand(1,100);
$ten = 'Quyển Sách '."$n";
$tacgia = "Tác Giả $n";
$gia = "$n";
$nxb = "Nhà Xuất Bản $n";
?>
<div class="container ">
<?=$ten?>
<table class="table table-bordered ">
<thead class="table-info">
<th>Tên</th>
<th>Tác Giả</th>
<th>Giá</th>
<th>Nhà xuất bản</th>
</thead>
<tbody>
<td><?=$ten?></td>
<td><?=$tacgia?></td>
<td><?=$gia?>VNĐ</td>
<td><?=$nxb?></td>
</tbody>
</table>
</div>
</body>
</html>