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