diff --git a/models/tourModel.js b/models/tourModel.js index ff73644f3db13172e1abb61f7e45470e356a4279..8f521245b605c86c55217cb500a6f330f64acafb 100644 --- a/models/tourModel.js +++ b/models/tourModel.js @@ -14,21 +14,23 @@ class Tour { } } - // ค้นหาทัวร์โดยใช้ชื่อ - static async searchTours(query) { + static async searchTours(req, res) { + const query = req.query.query; try { - - const [rows] = await pool.query('SELECT * FROM tours WHERE name LIKE ?', [`%${query}%`]); - // หากไม่มีทัวร์ที่ตรงกับคำค้นหา - if (rows.length === 0) { - return 'ไม่พบทัวร์ที่ตรงกับคำค้นหาของคุณ'; + const tours = await Tour.searchTours(query); + + // ถ้าไม่มีทัวร์ในผลลัพธ์ + 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) { diff --git a/views/edittour.ejs b/views/edittour.ejs index 57ee9a31448640c95dbde0d525b69b8c715ba93f..90bbc56a38e848395ed2d9cac56bf6dfc7072c8c 100644 --- a/views/edittour.ejs +++ b/views/edittour.ejs @@ -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>