Jump to content

Help creating a conditional statement?


knox203

Recommended Posts

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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.