Gitlab@Informatics

Skip to content
Snippets Groups Projects
Commit 07035be0 authored by 65160394's avatar 65160394
Browse files

Project Round 6

parent 0d3e9535
No related branches found
No related tags found
No related merge requests found
......@@ -14,22 +14,24 @@ class Tour {
}
}
// ค้นหาทัวร์โดยใช้ชื่อ
static async searchTours(query) {
static async searchTours(req, res) {
const query = req.query.query;
try {
const tours = await Tour.searchTours(query);
const [rows] = await pool.query('SELECT * FROM tours WHERE name LIKE ?', [`%${query}%`]);
// หากไม่มีทัวร์ที่ตรงกับคำค้นหา
if (rows.length === 0) {
return 'ไม่พบทัวร์ที่ตรงกับคำค้นหาของคุณ';
// ถ้าไม่มีทัวร์ในผลลัพธ์
if (tours.length === 0) {
console.log('ไม่พบทัวร์ที่ค้นหา');
}
return rows;
res.render('search', { tours });
} catch (error) {
console.error('Error searching tours:', error.message);
throw new Error('เกิดข้อผิดพลาดในการค้นหาทัวร์');
res.render('search', { tours: [] });
}
}
// สร้างทัวร์
static async createTour(name, description, price, duration) {
// ตรวจสอบข้อมูล
......
......@@ -9,7 +9,6 @@
<body>
<main>
<h1>Edit Tour</h1>
<br>
<form action="/edit/<%= tour.id %>" method="POST">
<div>
<label for="tourName">Tour Name:</label>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment