php - how to create the sql_query -
i have created filters in php.3 of them aimming 1 table. 4th aimming table. first table :
id_of_orders : id_order(int) time(now) username(varchar) price(decimal)
the second 1 :
order : order_id(int) product(varchar) price (decimal)
order.order_id
refered id_of_orders.id_order
table id_of_orders mapper orders table (id_of_orders.id_order
has unique numbers). table orders contains many orders of them have same order_id
i want return id_of_orders.id_order contain order.product=='proion'
the query use this:
$query = "select * id_of_orders 1=1"; if(!empty($_session['employees'])) $query .= " , id_of_orders.username='$_session[employees]'"; if(!empty($_session['timis'])) $query .= " , id_of_orders.price='$_session[timis]'"; if(!empty($_session['dates'])) $query .= " , date(time)='$_session[dates]'"; //if(!empty($_session['proions'])) // $query .= " , (orders.product='$_session[proions]' && id_of_orders.id_order==orders.order_id)"; $result = mysql_query($query);
you can try query like
select o.* id_of_orders join ( select order_id orders product = 'proion' group order_id ) q on i.id_order = q.order_id o.username = ? , o.price = ? , date(time) = ?
or
select i.id_order, i.time, i.username, i.price id_of_orders join orders o on i.id_order = o.order_id 1 = 1 , o.product = 'proion' , o.username = ? , o.price = ? , date(time) = ? group i.id_order, i.time, i.username, i.price
Comments
Post a Comment