mysql: comparing 2 fields
got a bit of a problem. im trying to select data from various tables, and i want to do kinda do a OR statement without it being an actual OR. confused? yep, so am i.
heres what i have:
$query = 'SELECT products_vendor AS vendor_id, o.orders_id AS orders_id, customers_name, UNIX_TIMESTAMP(date_purchased) AS date_purchased, orders_status ';
$query .= 'FROM orders AS o, orders_products AS op, products AS p ';
$query .= "WHERE o.orders_id = op.orders_id AND op.products_id = p.products_id AND p.vendors_id = '".intval($_SESSION['vendor_id'])."' ";
switch ($filter){
case 'delivered':
$query .= 'AND orders_status = 3 ';
break;
case 'pending':
$query .= 'AND orders_status = 1 ';
break;
case 'processing':
$query .= 'AND orders_status = 2 ';
break;
}
$query .= ' GROUP BY o.orders_id ORDER BY date_purchased DESC ';
from this you'll see it only selects the order details where the product ordered belongs to the certain "vendor" thats logged in.
now with a recent update to the system, i've been asked to make it so that even if a product is removed from products table, it will still display in the order. SO i've added a field "products_vendor" to the table "orders_products", and the products_vendor contains the vendor id.
so what i want to do is…. SELECT all the order details FROM the various order tables WHERE products_id belongs to vendor OR products_vendor = VENDOR LOGGED IN
i've tried using a MATCH(p.products_id, op.products_vendor) AGAINST (vendor id) but i get mysql errors that are because its not setup as a FULL TEXT search in the table properties.
anyone have enough mysql / php experiance to be able to help me out with this query?