knox203 Posted June 6, 2008 Share Posted June 6, 2008 Hey all, I'm pulling a big brain fart... I'm using this first query to grab jobs for a pay period (usually 7 days) after the user selects a month and billing cycle: <?php $ic = " SELECT id, dts, driver, date, job, pay_period, round(base,2) as base_round FROM $databasename.$databasetable WHERE driver = '$username' AND left(dts, 15) = '$dts_select' AND pay_period = '".$_POST['pay_period']."'"; ?> I then created this second query which grabs the values I'm going to need to use in a conditional statement: <?php $count = " SELECT date, count(date) as job_count, sum(base) as base_count FROM d_ic_accounting.commission_report WHERE driver = '$username' AND left(dts, 15) = '$dts_select' AND pay_period = '".$_POST['pay_period']."' GROUP BY date"; ?> I need the conditional statement to be like this: A driver must have at least ten jobs per day OR bring in at least $120.00 per day... can anyone please help me create this condition? It seems like it should be really easy, but I'm having a hard time figuring it out. Thanks! Quote Link to comment Share on other sites More sharing options...
discomatt Posted June 6, 2008 Share Posted June 6, 2008 Pretty sure you can do this using pure MySQL.. you may want to take the question over to that forum... I could probably build a query for you with a bit of sample data, but I'd be going by trial and error and may take a few minutes. Quote Link to comment Share on other sites More sharing options...
knox203 Posted June 6, 2008 Author Share Posted June 6, 2008 Thanks for the reply, Matt. I don't mind troubleshooting it a bit, I probably won't want to do it with pure MySQL because I'm going to need to include a couple other things into the condition... this is just the part I'm having a hard time with. Here's what I thought might work, but was sadly mistaken! <?php while ($count_result = mysql_fetch_assoc($count_query)); { if ( $count_result['job_count'] >= '10' && $yes_status_result && array_sum($paid_total) < "350" || $count_result['base_count'] >= "120" && $yes_status_result && array_sum($paid_total) < "350" ) { $grand_total = "350.00"; } else { $grand_total = number_format(array_sum($paid_total) + $gas_addition, 2); } } ?> I hope that doesn't look too confusing to you, anyways, what I'm trying to achieve with this is to echo out $350 if the driver meets all the conditions, but if they don't meet all of them, they get what they earned (which is less than $350). Kind of a "starters guarantee" if you will. Quote Link to comment Share on other sites More sharing options...
discomatt Posted June 6, 2008 Share Posted June 6, 2008 Wanna send me some sample data and conditions? I'll see what i can muck up. The trick here is making things as efficient as possible, rather than hacking together a solution If you just want something hacked together, let me know. I like to avoid providing it as a 'solution' though... Quote Link to comment Share on other sites More sharing options...
knox203 Posted June 6, 2008 Author Share Posted June 6, 2008 <Unnecessary post...> Quote Link to comment Share on other sites More sharing options...
discomatt Posted June 6, 2008 Share Posted June 6, 2008 Sorry, i meant sample data, as in database data Didn't mean to make you reveal your code Quote Link to comment Share on other sites More sharing options...
knox203 Posted June 6, 2008 Author Share Posted June 6, 2008 I see, how do you want the sample data... in a .sql file? You could also just hack something together if you'd like... I could probably end up building on it and making it more efficient. Whichever is easiest for you man! 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.