我可以在一个程序中有多个while(!feof)循环吗?

时间:2016-07-15 15:38:15

标签: php

如果我正在尝试显示一个表(我已经用while循环完成了),但也显示了一个计数。我是否添加了另一个while循环?或者单独循环?我该怎么办?我需要计算表演的数量(我已经开始工作了),但它并不算是阿什维尔的表演数量。我如何自己定位该变量?

>   <?php       print ("<h1>Upcoming Performances in 2015</h1>");       print
> ("<table border =\"1\">");        print("<tr><th align =
> \"left\">Date</th><th align = \"left\">Venue</th><th align =
> \"left\">City</th><th align = \"right\">Ticket Price</th></tr>");
> 
>       $count = 0;         $ashevilleCount = 0;        $eventFile =
> fopen("performances.txt", "r");       $schedule = fgets($eventFile);
> 
>       
>               while(!feof($eventFile))        {           list($date, $venue, $city, $ticketPrice) =          explode(":", $schedule);
>                       print("<tr><td>$date</td>");            print("<td>$venue</td>");           print("<td>$city</td>");            print("<td>$ticketPrice</td>");
>                       $schedule = fgets($eventFile);
>                   }
>       
>                           for($count = 1; $count <= 5; $count = $count + 1)       {           $total = fgets($eventFile);             $count = $count + $total;
>                   }
>               if ($city == Asheville)
>               $ashevilleCount = $ashevilleCount + $count;
>       
>   
>       
>       
>       
>                   fclose($eventFile);
>               print ("</table>");
> 
>       print ( "<p class=\"alert\">Lower cost venues are marked with
> *</p>");      print ("<p>NUMBER OF PERFORMANCES: $count</p>");        print ("<p>NUMBER OF PERFORMANCES IN ASHEVILLE: $ashevilleCount</p>");
>       
>       
>               
> 
> ?>

2 个答案:

答案 0 :(得分:0)

您需要查看if语句。

if($condition === true){
    //executes if $condition is true
} elseif($condition === 1) {
    //executes if $condition is 1
} elseif($condition === 2 || $condition === 3){
    //executes if $condition is 2 OR condition is 3
} elseif($condition === 4 && $otherCondition !== "foo"){
    //executes if $condition is 4 AND $otherCondition is NOT "foo"
} else {
    //executes if no other statements are true
}

这段代码:

 elseif
 ($charType == human or dwarf and $goldSpent <= 10)
 $supplyTokens = $_POST['supplyTokens'] + 10;

需要看起来像:

 } elseif( ( $charType=="human" || $charType=="dwarf" ) && $goldSpent <= 10) {
      $supplyTokens = $_POST['supplyTokens'] + 10;
 }

记住:

  • || =&#34;或&#34;
  • && =&#34;和&#34;
  • test!= "test" - 确保您的字符串用引号括起来

请参阅:

答案 1 :(得分:0)

您的代码已清理完毕。做了什么:

  • 将所有isbns<- c("9785170922789", "9785170804801", "9785699834174", "9785699717255", "9785170869237") getISBNprice <- function(ISBN, source="http://www.knigoed.info/api/Prices?code=") { pathA <- source for (i in 1:length(ISBN)) { ISB <- ISBN[i] AAA <- paste(pathA, ISB, "&sortPrice=DESC&country=RU", sep="") document <- fromJSON(AAA, flatten = FALSE) dfp <- document$prices dfp <- cbind(dfp,ISB ) # dfp <- cbind(dfp,BookID=document$bookId) # dfp <- cbind(dfp,Title=document$title) # dfp <- cbind(dfp,Author=document$author) # dfp <- cbind(dfp,Publisher=document$publisher) # dfp <- cbind(dfp,Series=document$series) # dfp <- cbind(dfp,Picture=document$picture) if (!exists("AAAA")) {AAAA<- dfp} else {bind_rows(AAAA, dfp) } } AAAA } 命令更改为连接print() s。
  • 修正了条件
    • 您不需要在echo中检查$goldSpent <= 10,因为您已经通过elseif中检查了
    • 我个人更喜欢$goldSpent > 10||,而不是&&or
  • 添加了大括号and

要考虑的事情:

  • 如果这些{}值中的任何一个为空,会发生什么?
$_POST