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 Link to comment https://forums.phpfreaks.com/topic/107879-solved-getting-values-from-array-for-a-conditional-loop/ 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. Link to comment https://forums.phpfreaks.com/topic/107879-solved-getting-values-from-array-for-a-conditional-loop/#findComment-553012 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 Link to comment https://forums.phpfreaks.com/topic/107879-solved-getting-values-from-array-for-a-conditional-loop/#findComment-553019 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.