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
https://forums.phpfreaks.com/topic/109054-help-creating-a-conditional-statement/
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.

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.

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

Archived

This topic is now archived and is closed to further replies.

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