Hi , I've been working on comparison query with PHP and MySql 5.0 yet not getting anywhere with it.
I'm trying to perform a search ( query )
I have several tables within the same database that contain same fields yet hold different data
eg
Table 1
id |Product | Price | Private
Table 2
id| Product | Price | Private
etc...
What I'm trying to do is have the ability to search the tables and display it as follows
Products (tables 1 & 2 ) | Price( Table 1 ) | Price (Table 2 )
I've been playing with UNION
$query = "Select `product`, `private` as p, 'table1' as n from `table1` where `name` REGEXP '".$trimmed."' UNION ALL Select `product`, `private` as p, 'table2' as n from `table2` where `name` REGEXP '".$trimmed."' ORDER by `product`";
Output in php as follows
while($row = mysql_fetch_array($result))
{
echo "<tr>";
//echo "<td>" . $row['Product'] . "</td>";
// echo "<td>" . $row['Product'] . "</td>";
// echo "<td>" . $row['private'] . "</td>";
// echo "<td>" . $row['id'] . "</td>";
// echo "<td>" . $row['table1.price'] . "</td>";
// echo "<td>" . $row['table2.price'] . "</td>";
// echo "</tr>";
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['n'] . "</td>";
echo "<td>" . $row['p'] . "</td>";
echo "</tr>";
}
So far I cannot seem to get the products nor pricing in line , any ideas ?