帮助进行条件操作
我对 PHP 有一些基础知识,并且我实际上理解下面的代码实际上是做什么的,但是我需要做一些更复杂的事情,我希望你能帮助我。
我是一个销售网站的管理员,我们与程序员之间发生了一些麻烦,他被我的老板解雇了,所以当我们寻找新的程序员时,我需要为此找到一个解决方案。
此代码执行以下操作:如果 $buyers 为 0,则显示消息“成为第一个购买它的人!”;如果等于1,则显示“1个买家”;如果等于 2(以此类推),则显示“2 个买家”;
<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>
但这仅适用于已获得信用卡公司批准的购买,因此,如果 30 人购买但实际上只有 2 人获得批准,则会显示“2 位买家”。
因此,我需要它显示“2 个买家 + 28 个待处理”,以便人们可以看到该产品实际上正在销售。
在控制付款的数据库中,我们有“买方”和“待处理”的表,因此很容易实现。我只是不明白如何,PHP 这不是我的领域,我只是在这里和那里弄清楚一些事情,因为我实际上是一名程序员,但对于另一种语言。
就这样,谢谢大家抽出时间。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
编辑:添加附加信息表明存在
$pending
变量后,代码将如下所示(请注意,这是未经测试的):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):您最好聘请一些自由职业者或自己学习。因为基本上你只是要求一些基本的 SQL 查找和回显。
然而,根据您提供的信息,我们无法帮助您。我希望它像“SELECT COUNT(*) FROM pending”一样简单,但事实可能并非如此。
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.
您应该能够回收买家的查询以确定待处理的情况。
你的代码应该看起来像这样(guesS)
请记住,这是对你使用的内容的基本猜测,但是你应该能够找到这段代码,用不同的变量名($sql2等)修改它并提取计数待定为 $pending 而不是 $buyers。
示例:
然后您可以重新使用上面发布的代码,并且
You should be able to recycle the query form the buyers to determine the pending.
Your code should look something like this (guesS)
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:
Then you can re-use the code you posted above, and