knox203 Posted May 29, 2008 Share Posted May 29, 2008 Hello everyone, I have a conditional statement inside of a do-while loop... before I get too ahead of myself, here's the code: do { if ( $fields['CustomerCode'] == "SYSCFOOD" && $job_date_name != "Sat" && $job_date_name != "Sun" && $fields['DriverBaseAmount'] > '14.00' || $fields['CustomerCode'] == "IVEYIMAG" && $job_date_name != "Sat" && $job_date_name != "Sun" && $fields['DriverBaseAmount'] > '14.00' || $fields['CustomerCode'] == "KAISLTC" && $job_date_name != "Sat" && $job_date_name != "Sun" && $fields['DriverBaseAmount'] > '14.00' || $fields['CustomerCode'] == "KAISPERM" && $job_date_name != "Sat" && $job_date_name != "Sun" && $fields['DriverBaseAmount'] > '14.00' || $fields['CustomerCode'] == "EVERPHAR" && $job_date_name != "Sat" && $job_date_name != "Sun" && $fields['DriverBaseAmount'] > '14.00' || $fields['CustomerCode'] == "CONSPHAR" && $job_date_name != "Sat" && $job_date_name != "Sun" && $fields['DriverBaseAmount'] > '14.00' || $fields['CustomerCode'] == "QUESSTAT" && $job_date_name != "Sat" && $job_date_name != "Sun" && $fields['DriverBaseAmount'] > '14.00' || $fields['CustomerCode'] == "LEGASTAT" && $job_date_name != "Sat" && $job_date_name != "Sun" && $fields['DriverBaseAmount'] > '14.00' ) { $fields['DriverBaseAmount'] = $fields['DriverBaseAmount'] - 2.50; } ....... } while ($fields = mssql_fetch_assoc($ic_result)); I need to add around 100 more company code names into this conditional statement, but I don't want the code to be huge! I figure there has to be a more efficient way of doing this. So can I add all of the company codes into an array, and just have one conditional statement look through the array while the do-while is looping? Thanks! - Adam Quote Link to comment Share on other sites More sharing options...
Millar Posted May 29, 2008 Share Posted May 29, 2008 $codes = array('SYSCFOOD','IVEYIMAG','ETC'); do { if (in_array($fields['CustomerCode'], $codes) && $job_date_name != "Sat" && $job_date_name != "Sun" && $fields['DriverBaseAmount'] > '14.00') { $fields['DriverBaseAmount'] -= 2.50; } } while ($fields = mssql_fetch_assoc($ic_result)); That should do the trick. Quote Link to comment Share on other sites More sharing options...
knox203 Posted May 29, 2008 Author Share Posted May 29, 2008 Works perfectly, thanks so much, Millar!! Appreciate the speedy solution. - Adam Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.