使用PHP在While循环中的下一个语句

时间:2014-05-01 13:25:39

标签: php while-loop

好的我在我的网站上有一个while循环函数,它可以获取excel文档并将它们分析到数据库我想检查重复项,如果重复则跳过它:

$content = file($selectfile1);

$posted_content = array();
list($rownum, $row) = each($content);
$posted_content[0] = explode(",", $row);
array_push($posted_content[0], "ID");
$count = 0;
// iterate each row (1 post)
while (list($rownum, $row) = each($content))
{
    $count++;

    $cols = "orderid, created_at, updated_at, notification_type, radius, available, expiration, ";
    $vals = "";
    $cols2 = "equipment_id";
    $vals2 = "";

....{parsing data)...
}

我想写一个脚本,检查记录是否重复,如果没有输入。

$sql25 = "SELECT * FROM notifications WHERE origin =" . $origin_id . " user_id =12039";
$rs25 = $conn->Execute($sql25);
if($rs25->RecordCount() == 1 || $rs25->RecordCount() >= 1)
    {



here is where i need a command. Can you use? next()
--------------------------------------------------


    }
else
{
         Insert query
    }

1 个答案:

答案 0 :(得分:1)

您正在寻找continue声明。

来自文档:

  循环结构中使用

continue来跳过当前循环迭代的其余部分,并在条件评估和下一次迭代开始时继续执行。

(见http://www.php.net/manual/en/control-structures.continue.php

示例:

<?php
while ( ... ) {
    if ($foo = 'bar') {
        // skip to the next iteration
        continue;
    }
}