mysql use the selected variable in the same query -
i have table 'booking_summary' stores type of method (method = air or sea). have join table 1 of 2 other tables depending on method column.
if method air,then table join booking_air,if sea booking_sea. not want run multiple queries on particular page.
this latest attempt,that has failed.the table_name alias table want in same query.
$sql = "select case when a.shipping_method = 'sea' 'booking_sea' else 'booking_air' end 'table_name', case when a.user_id ='$active_id' 'y' else 'no' end 'generate_access', case when c.mbl null 'pending' else c.mbl end 'mbl_status', case when c.hbl null 'pending' else c.hbl end 'hbl_status', a.*,b.user_name booking_summary left join registered_users b on a.user_id = b.user_id left join table_name c on a.id = c.id (a.user_id = '$active_id' or a.forwarder='$active_id')";
any advice helpful. thanks
om i'm not sure if going work but, anyhow...
$sql = "select case when a.user_id ='$active_id' 'y' else 'no' end 'generate_access', if(a.shipping_method = 'sea', case when c.mbl null 'pending' else c.mbl end, case when d.mbl null 'pending' else d.mbl end ) 'mbl_status', if(a.shipping_method = 'sea', case when c.hbl null 'pending' else c.hbl end, case when d.hbl null 'pending' else d.hbl end ) 'hbl_status', a.*,b.user_name booking_summary left join registered_users b on a.user_id = b.user_id left join booking_sea c on a.id = c.id left join bookin_air d on a.id=d.id (a.user_id = '$active_id' or a.forwarder='$active_id')";
Comments
Post a Comment