0

I have tried to retrieve data from a database and then compare it with a variable and using for loop and continue to skip numbers found in the database but it only skips the first number from loop this what i want to do with the data

  • To count the number of loops (how many vouchers not posted)
  • To also know the vouchers that are not posted in the dbase so as to input new voucher numbers in database after all the last ones are all used This is my code:

    $hostname = "localhost";
    $user = "****";
    $pass = "*******";
    $database = "test";
    $connection = mysql_connect($hostname, $user, $pass) or die(mysql_error());
    mysql_select_db($database, $connection) or die(mysql_error());
    $from = 1001;
    $to = 2000;
    $query="SELECT * FROM voucher_posted WHERE voucher BETWEEN '$from' AND '$to' ORDER BY  voucher ASC";
    $squery=mysql_query($query) or die (mysql_error());
    while($array=mysql_fetch_array($squery)){$voucher[]=$array['voucher'];}
    for($from;$from<=$to;$from++)
    {
    foreach($voucher as $vouchers)
    if($from==$vouchers){continue;}
    echo $from.'<br/>';
     }
    

Thanks in advance Derrick

4

1 回答 1

0

您的 continue 仅继续内部foreach。要继续外部for,请使用

continue 2;

php.net

此致

佐尔特

于 2013-05-17T13:48:21.417 回答