[英]How can I skip a row when using mysql_fetch_assoc?
I am currently running a query that looks like this: 我当前正在运行如下查询:
SELECT campaigns.id, lead_stats.camp_id, lead_stats.country, campaigns.name, SUM(lead_stats.leads) AS lead, SUM(lead_stats.clicks) AS click,TRUNCATE(100.0 * SUM(lead_stats.leads) / SUM(lead_stats.clicks), 1) AS conv_rate
FROM lead_stats
JOIN campaigns
ON campaigns.id = lead_stats.camp_id
WHERE lead_stats.date > DATE_SUB(NOW(), INTERVAL 24 HOUR)
AND lead_stats.from_product = 4
AND lead_stats.camp_id NOT IN (
SELECT camp_id
FROM suspicious_offer_clears
WHERE clear_until > '".date('Y-m-d H:i:s')."'
AND alert_type = 3
)
GROUP BY lead_stats.camp_id
HAVING (SUM(lead_stats.leads) / SUM(lead_stats.clicks)) < 0.1
ORDER BY lead_stats.camp_id
It gets some information that is not important really for my question that I have. 它得到的一些信息对于我所遇到的问题并不真正重要。 However, I was curious on how I could, in this SQL statement, do an if statement on the lead_stats.country. 但是,我很好奇如何在此SQL语句中对lead_stats.country执行if语句。 I want to see if the country is NOT equal to "US", and if it is NOT equal to "US" I want to see if the SUM(lead_stats.click) for that row is greater than 20. I decided I would try to do it in my php template because I could not figure out how to do on MySQL. 我想查看该国家/地区是否不等于“ US”,如果它不等于“ US”,我想查看该行的SUM(lead_stats.click)是否大于20。我决定尝试在我的php模板中执行此操作,因为我不知道如何在MySQL上执行操作。
Here is what I have on my template for that. 这是我模板上的内容。
<?php
while ( $row = mysql_fetch_assoc($getConresult) ) {
if($row['country'] != "US"){
if($row['click'] > 19){
//not sure what to do here because it is less than 20, so I do not want to include this in my output on the table
}
}
So I am wondering how I can skip a record if it does not match my criteria stated above. 因此,我想知道如果记录不符合上述条件,我该如何跳过该记录。 I was thinking I could use a for statement but had some confusion on that front. 我当时以为可以使用for语句,但是在这方面有些困惑。 Any help would be appreciated! 任何帮助,将不胜感激!
Because it's a while
loop, you should just skip that iteration 因为是while
循环,所以您应该跳过该迭代
while ( $row = mysql_fetch_assoc($getConresult) ) {
if($row['country'] != "US"){
if($row['click'] < 20){
continue; //skip to the next loop
}
}
If you need to stop the loop, use break instead of continue 如果需要停止循环,请使用break而不是Continue
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.