PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
CREATE TABLE singers ( id INT AUTO_INCREMENT PRIMARY KEY, name TEXT NOT NULL, pronunciation TEXT NOT NULL, created_at DATETIME DEFAULT CURRENT_TIMESTAMP, updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP ); CREATE TABLE genres ( id INT AUTO_INCREMENT PRIMARY KEY, name TEXT NOT NULL, created_at DATETIME DEFAULT CURRENT_TIMESTAMP, updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP ); CREATE TABLE songs ( id INT AUTO_INCREMENT PRIMARY KEY, name TEXT NOT NULL, pronunciation TEXT NOT NULL, singer_id INT NOT NULL, genre_id INT, created_at DATETIME DEFAULT CURRENT_TIMESTAMP, updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, FOREIGN KEY (singer_id) REFERENCES singers (id), FOREIGN KEY (genre_id) REFERENCES genres (id) ); CREATE TABLE reservations ( id INT AUTO_INCREMENT PRIMARY KEY, song_id INT NOT NULL, created_at DATETIME DEFAULT CURRENT_TIMESTAMP, updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, FOREIGN KEY (song_id) REFERENCES songs (id) ); INSERT INTO singers (name, pronunciation) VALUES ('Creepy Nuts(R-指定&DJ松永)', 'クリーピーナッツアールシテイアンドディージェイマツナガ'); INSERT INTO singers (name, pronunciation) VALUES ('高橋洋子', 'タカハシヨウコ'); INSERT INTO singers (name, pronunciation) VALUES ('YOASOBI', 'ヨアソビ'); INSERT INTO singers (name, pronunciation) VALUES ('Vaundy', 'バウンディ'); INSERT INTO singers (name, pronunciation) VALUES ('中川翔子', 'ナカガワショウコ'); INSERT INTO singers (name, pronunciation) VALUES ('tuki.', 'ツキ'); INSERT INTO singers (name, pronunciation) VALUES ('優里', 'ユウリ'); INSERT INTO singers (name, pronunciation) VALUES ('あいみょん', 'アイミョン'); INSERT INTO singers (name, pronunciation) VALUES ('back number', 'バックナンバー'); INSERT INTO singers (name, pronunciation) VALUES ('Mrs.GREEN APPLE', 'ミセスグリーンアップル'); INSERT INTO singers (name, pronunciation) VALUES ('Saucy dog', 'サウシードッグ'); INSERT INTO singers (name, pronunciation) VALUES ('aiko', 'アイコ'); INSERT INTO singers (name, pronunciation) VALUES ('菅田将暉', 'スダマサキ'); INSERT INTO singers (name, pronunciation) VALUES ('Taylor Swift', 'テイラー・スウィフト'); INSERT INTO singers (name, pronunciation) VALUES ('シャルル', 'シャルル'); INSERT INTO singers (name, pronunciation) VALUES ('美空ひばり', 'ミソラヒバリ'); INSERT INTO genres (name) VALUES ('-'); INSERT INTO genres (name) VALUES ('アニメ'); INSERT INTO genres (name) VALUES ('ボーカロイド'); INSERT INTO genres (name) VALUES ('演歌'); INSERT INTO genres (name) VALUES ('洋楽'); INSERT INTO songs (name, pronunciation, singer_id, genre_id) VALUES ('Bling-Bang-Bang-Born', 'ブリンバンバンボン', 1, 2); INSERT INTO songs (name, pronunciation, singer_id, genre_id) VALUES ('残酷な天使のテーゼ', 'ザンコクナテンシノテーゼ', 2, 2); INSERT INTO songs (name, pronunciation, singer_id, genre_id) VALUES ('残酷な天使のテーゼ', 'ザンコクナテンシノテーゼ', 5, 2); INSERT INTO songs (name, pronunciation, singer_id, genre_id) VALUES ('アイドル', 'アイドル', 3, 2); INSERT INTO songs (name, pronunciation, singer_id, genre_id) VALUES ('夜に駆ける', 'ヨルニカケル', 3, 1); INSERT INTO songs (name, pronunciation, singer_id, genre_id) VALUES ('怪獣の花唄', 'カイジュウノハナウタ', 4, 1); INSERT INTO songs (name, pronunciation, singer_id, genre_id) VALUES ('タイムパラドックス', 'タイムパラドックス', 5, 2); INSERT INTO songs (name, pronunciation, singer_id, genre_id) VALUES ('晩餐歌', 'ばんさんか', 6, 1); INSERT INTO songs (name, pronunciation, singer_id, genre_id) VALUES ('ドライフラワー', 'ドライフラワー', 7, 1); INSERT INTO songs (name, pronunciation, singer_id, genre_id) VALUES ('マリーゴールド', 'マリーゴールド', 8, 1); INSERT INTO songs (name, pronunciation, singer_id, genre_id) VALUES ('水平線', 'スイヘイセン', 9, 1); INSERT INTO songs (name, pronunciation, singer_id, genre_id) VALUES ('高嶺の花子さん', 'タカネノハナコサン', 9, 1); INSERT INTO songs (name, pronunciation, singer_id, genre_id) VALUES ('青と夏', 'アオトナツ',10, 1); INSERT INTO songs (name, pronunciation, singer_id, genre_id) VALUES ('ケセラセラ', 'ケセラセラ',10, 1); INSERT INTO songs (name, pronunciation, singer_id, genre_id) VALUES ('シンデレラボーイ', 'シンデレラボーイ',11, 1); INSERT INTO songs (name, pronunciation, singer_id, genre_id) VALUES ('いつか', 'イツカ',11, 1); INSERT INTO songs (name, pronunciation, singer_id, genre_id) VALUES ('カブトムシ', 'カブトムシ',12, 1); INSERT INTO songs (name, pronunciation, singer_id, genre_id) VALUES ('虹', 'ニジ',13, 2); INSERT INTO songs (name, pronunciation, singer_id, genre_id) VALUES ('Love Story', 'ラブストーリー',14, 5); INSERT INTO songs (name, pronunciation, singer_id, genre_id) VALUES ('22', 'トゥエンティートゥー',14, 5); INSERT INTO songs (name, pronunciation, singer_id, genre_id) VALUES ('バルーン', 'バルーン',15, 3); INSERT INTO songs (name, pronunciation, singer_id, genre_id) VALUES ('川の流れのように', 'カワノナガレノヨウ二',16, 4);
Copy Clear
Copy Format Clear
<?php // Assuming $mysqli is already defined and connected to the database // User input (example: using GET parameter) $searchTerm = isset($_GET['search']) ? $_GET['search'] : ''; // Prepare and execute SQL query $sql = " SELECT songs.name AS song_name, singers.name AS singer_name FROM songs JOIN singers ON songs.singer_id = singers.id WHERE songs.name LIKE ? OR songs.pronunciation LIKE ? ORDER BY songs.pronunciation ASC LIMIT 10 "; $stmt = $mysqli->prepare($sql); $likeSearchTerm = '%' . $searchTerm . '%'; $stmt->bind_param('ss', $likeSearchTerm, $likeSearchTerm); $stmt->execute(); $result = $stmt->get_result(); // HTML output echo "<h1>Search Results</h1>"; echo "<table border='1'>"; echo "<tr><th>Song Name</th><th>Singer Name</th></tr>"; while ($row = $result->fetch_assoc()) { echo "<tr>"; echo "<td>" . htmlspecialchars($row['song_name'], ENT_QUOTES, 'UTF-8') . "</td>"; echo "<td>" . htmlspecialchars($row['singer_name'], ENT_QUOTES, 'UTF-8') . "</td>"; echo "</tr>"; } echo "</table>"; $stmt->close(); ?>
Show:  
Copy Clear