PHP If else statement with exception

i have some code that im editing for an auction website, the thing is that i need the $all_unpaid = false if the bid_amount is zero, I tried several tweaks but no results, perhaps some1 can have some suggestions?

[php]function direct_payment_multiple ($invoice_id, $items_array, $dp_array, $buyer_id)
{
$output = false;

	$nb_sub_arrays = count($dp_array);
	if ($nb_sub_arrays)
	{
		$array_result = $dp_array[0];
		
		for ($i=1; $i<$nb_sub_arrays; $i++)
		{
			$array_result = @array_intersect($array_result, $dp_array[$i]);
		}
		
		$all_unpaid = true;
		for ($i=0; $i<$nb_sub_arrays; $i++)
		{
			$all_unpaid = (!$items_array[$i]['direct_payment_paid'] && !$items_array[$i]['flag_paid'] && $items_array[$i]['bid_amount'] > 0) ? $all_unpaid : false;
		}

		$same_currency = true;
		$currency = $items_array[0]['currency'];
		for ($i=0; $i<$nb_sub_arrays; $i++)
		{
			$same_currency = ($currency == $items_array[$i]['currency']) ? $same_currency : false;
		}
	}
	
	$output = (is_array($array_result) && $all_unpaid) ? true : false;
	
	return $output;
}[/php]

some overview some overview, this auction website allows users to place a bid of 0.00, if no-one outbids them then they get the item for free, however if someone does outbid them then regular code applies so if payment has been made and is greater then zero then all_unpaid is true, if payment equal to zero or there is no payment then all_unpaid is false

So,
(0.00 is valid)
$all_unpaid=true;
if bid_amount=0 then $all_unpaid=false;
if any-bid>0 and payment>0 then $all_unpaid=true;
if any-bid>0 and payment=0 then $all_unpaid=false;

Assuming that is your requirements… That looks straight forward… Not sure what your question is.
We can help you sort it out without much effort.

BUT, you need to help us help you… The variables in your code do not match what you said in your text.
We need to know what each variable is used for. Basically, when you sort thru the invoices and items using the $i, which variable in the inside compare to assign false to $all_unpaid is which. Which is the original bid you are checking on, which is the any-bid and etc… Clear us up a little and we can show you the correct IF to fix it up for you…

$all_unpaid has 3 variables that it checks direct_payment_paid, flag_paid and bid_amount, the values for direct_payment_paid is 1 (success) or 0 (fail) flag_paid has 1 (success) or 0 (failed) and the bid_amount checks the winning bid price if it is greater then zero, while the direct_payment_paid checks if the buynow option was used,

so here is how i want it to work

auction listed, with bidding or buynow option
if auction closes with no bids then do nothing
if auction closes with bid of 0.00 then $all_unpaid is false
if auction closes with bid of greater then 0 then $all_unpaid is true
if auction closes with buyer using buynow option, then $all_unpaid is true

hope this clears things up

Not clear on the $all_unpaid flag or what you do with the results. I will print this later and look deeper.

So, based on your list, only one instance rings “false”, so the logic would be something like this…

looping thru all CLOSED auctions listed…
(if no CLOSED auctions listed, exit…)
looping thru all bids for the current listed CLOSED auction
(if no bids for this auction, exit…)
=======at this point, closed auction selected, a bid found========
$all_unpaid=true; //if bid is great than 0 true, if buyer buynow true…
if (bid_amount=0)
$all_unpaid=false; //Only instance which was false in your list, all others ring true…
end looping thru bids…Do next one.
//looped thru all bids, now handle $all_unpaid results
end looping for CLOSED auctions, do not one…

Maybe that will help, if not, I will look at it later in the day…

the flag is used to manually confirm payment received from the seller side,

the problem right now is when the bid_amount is zero it is still saying its unpaid
i need the code to reflect that when the bid_amount is zero then $all_unpaid should be false

So, basically my last post gave you the breakdown of the steps you need to test the
various variables. Review what I mentioned and let me know any other questions.

If your code doesn’t work, it is just a logic issue, nothing else. The rest looked okay.
Just the sequence of the IF’s have to be figured out. Separate them instead of just
assigning them as one line… Then we can see where it fails… Later…

how would it look seperated?

if direct_payment_paid = 0, all_unpaid= true

if flag_paid = 0; all_unpaid = true

if bid_amount = 0, all_unpaid = false

??

Yes, re-reading your original layout:

“so here is how i want it to work
auction listed, with bidding or buynow option
if auction closes with no bids then do nothing
if auction closes with bid of 0.00 then $all_unpaid is false
if auction closes with bid of greater then 0 then $all_unpaid is true
if auction closes with buyer using buynow option, then $all_unpaid is true”

And, your last post:

“how would it look seperated?
if direct_payment_paid = 0, all_unpaid= true
if flag_paid = 0; all_unpaid = true
if bid_amount = 0, all_unpaid = false”

It looks like it should be some similar to:
id ($bid_count==0)
//exit, as no bids were made (Not sure of your code for that, but, if a bid was made, continue)
$all_unpaid = “true”; //All results you showed above are true except on which follows…
if ($bid_amount=0)
$all_unpaid=“false”; // So, here a bid was made and it was zero, so now the results is false…

At least, that is what I see from what you have asked. If this does not make sense or doesn’t work, please post your latest code again and we can look at it further… Good luck…

Sponsor our Newsletter | Privacy Policy | Terms of Service