I'm trying to create a search form for a CD collection from two tables within the same SQL.
The search form for the Category portion, there are over 50 category, do i have to manual enter each or there's a way to make it dynamic ?
<form id = "getCD" method = "get"
action = "SearchBy.php">
Title
<input type = "search" name = "CDTitle" />
Year
<input type = "search" name = "CDYear" />
Category
<select name="CDCategory">
<option value="Acid Jazz"> </option>
<option value="Acid Jazz">Acid Jazz</option>
<option value="Afro-Beat">Afro-Beat</option>
</select>
<input type = "submit" value = "Search" />
</form>
For the 2nd portion in Search.php, I'm struggling with getting both table to join. I'm trying SQL ... JOIN...ON but encounter error.
<?php
include 'database_conn.php'; // make db connection
$pCDTitle = $_GET['CDTitle'];
$pCDYear = $_GET['CDYear'];
$pCDCategory = $_GET['CDCategory']; // store the parameter in a variable
$sqlCD = "SELECT nmc_cd.CDID, nmc_cd.CDTitle, nmc_cd.CDYear, nmc_cd.CDPrice
FROM nmc_cd
JOIN nmc_category on (nmc_cd.catID = nmc_category.catID)
WHERE nmc_cd.CDTitle = '$pCDTitle' OR nmc_cd.CDYear = '$pCDYear' OR nmc_category.catDesc = '$pCDCategory'";
$rsCD = mysqli_query($conn, $sqlCD)
or die(mysqli_error($conn));
while ($CD = mysqli_fetch_assoc($rsCD)) {
$title = $CD['CDTitle'];
$year = $CD['CDYear'];
$price = $CD['CDPrice'];
$category = $CD['CDCategory'];
echo "<div>$title, $year, $price, $category</div>\n";
}
mysqli_free_result($rsCD);
mysqli_close($conn);
?>
[ATTACH]5259[/ATTACH]
[ATTACH]5261[/ATTACH]
nmc_cd.jpg
nmc_cat.jpg