I’m trying to make a search form that displays data from my database where the name of the data is like the search term.
Sadly I’m trying to get it to echo information from multiple tables:
Album Table:
albumName albumArt artistID
---------- ---------- ---------
album1 art1.jpg 1
album2 art2.jpg 2
album3 art3.jpg 3
SongsTable:
songName artistID
-------- ---------
song1 1
song2 1
song3 2
song4 3
song5 3
Example PHP:
$search = $_POST['search'];
$sql1 = "SELECT * FROM songs WHERE songName LIKE '%$search%'";
$searchResult = mysql_query($sql1);
while ($result = mysql_fetch_array($searchResult)) {
echo "<tr>
<td>".$result['songName']."</td>
<td>".$result['albumName']."</td>
</tr>";
}
?>
I’m not sure if inner join will do the trick, I’ve read as many possible tutorials on this but none i can comprehend or use.
The search term is coming from an form on another page, this is just the processing page, but it also echos the information.
I need the query to return something similiar to below if someone searched ‘S’:
songName albumname artistName
---------- ---------- ---------
song1 album1 artist1
song2 album2 artist2
song3 album3 artist3
The most straightforward join I can imagine is this:
Btw, you should really escape your variables properly:
And some characters have a meaning with
LIKE, such as%and_; consider escaping those as well.