Reputation: 33
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.
Upvotes: 0
Views: 89
Reputation: 6158
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>
Upvotes: 1
Reputation: 4778
You should be able to recycle the query form the buyers to determine the pending.
Your code should look something like this (guesS)
$sql = mysql_query("SELECT COUNT(*) FROM buyers WHERE product_id={$someid}");
$buyers = mysql_fetch_object($sql);
Keep in m ind this is basic guess at what you use, but you should be able to find this code, modify it with different variable names($sql2, etc) and extract the count of pending to $pending instead of $buyers.
Example:
$sql2 = mysql_query("SELECT COUNT(*) FROM pending WHERE product_id={$someid}");
$pending = mysql_fetch_object($sql);
Then you can re-use the code you posted above, and
<p class="Lato"><?php echo $peding==0 ? "No Pending" : $pending . " Pending"; ?>
Upvotes: 1
Reputation: 4583
You better just hire some freelancer or learn it yourself. Because basically you're just asking for some basic SQL look up and echo'ing.
Nevertheless, with the info you supplied, we can not help you. I wish it was as simple as "SELECT COUNT(*) FROM pending", but it probably isn't.
Upvotes: 1