I have two tables, Chemicals & Consumables. "Chemicals" stores all of the general info about the chemicals (formula, safety etc) and "Consumables" stores information about stock & location in various rooms etc. The common field is "CAS" (Chemical Abstract Service Registry Number - a combination of numbers and hyphens).
I would like to search the "Chemicals" Table and return information from both tables
Question #1 - should I join them in the database (Navicat) or just through the php query?
Question #2 - why won't the following code work?
$item = $_POST['item'];
$chem = mysql_query("
SELECT *
FROM Chemicals
INNER JOIN Consumables
ON Chemicals.Name_Chem1 = '%$item%'");
while ($row = mysql_fetch_array($chem)){
echo
"<table border='0'>
<tr class='content'>
<th>Name</th>
<th>Quantity</th>
<th>GHS Code</th>
<th>Formula</th>
<th>CAS</th>
</tr>";
while($row = mysql_fetch_array($chem))
{
echo "<tr>";
echo "<td class='content'>" . $row['Consumables.Name'] . "</td>";
echo "<td class='content'>" . $row['Consumables.Quantity'] . "</td>";
echo "<td class='content'>" . $row['Chemicals.GHS_1'] . "</td>";
echo "<td class='content'>" . $row['Chemicals.Formula'] . "</td>";
echo "<td class='content'>" . $row['CAS'] . "</td>";
echo "</tr>";
}
echo "</table>";
}