I have some basic knowledge in PHP, and I actually understand what the code below actualy does, but I need to do a thing a little bit mor complex and I hope you can help me.
I am the admin of a sales website, we had some troubles with the programmer and he got fired by my boss, so while we are looking for a new programmer I need to come up with a solution for this.
This code does the following: if $buyers is 0, then it displays the message "Be the first to buy it!"; if it's equal 1, then it displays "1 buyer"; if it's equal 2 (and so), then it displays "2 buyers";
<p class="Lato"><?php echo $buyers==0 ? "Be the first to buy it!" : $buyers ; ?><?php echo intval($buyers)>0 ? intval($buyers)>1 ? " buyers" : " buyer" :"" ?></p>
But this is only for the purchases already approved by the credit card companies, so if 30 people bought it but only 2 were actually approved, it will display "2 buyers".
So, I need it to display "2 buyers + 28 pending" so people can see that the product is actually selling.
On the database that controls payment, we have the tables for "buyer" and for "pending" so it's easy to implement that. I just can't figure out how, PHP it's not my area, I just figure out some things here and there because I'm actually a programmer, but for another language.
That's it thank you guys for your time.
Edit: After the additional information was added saying that there is a $pending
variable, the code would be something like this (beware, this is untested):
<p class="Lato">
<?php
$buyersOutput = intval($buyers)>0 ? intval($buyers)>1 ? " buyers" : " buyer" :"" ;
$pendingOutput = intval($pending)>0 ? $pending . " pending" : "";
if ($buyers == 0 && $pending == 0) {
echo "Be the first to buy it!";
} else if (intval($buyers) > 0 && intval($pending) > 0) {
echo $buyersOutput ." + " . $pendingOutput;
} else { //if just one contains text
echo $buyersOutput . $pendingOutput;
}
?>
</p>