douling6469 2016-03-14 03:07
浏览 92

PHP和HTML混合:多个如果语句正确

So, I'm using a mix of PHP and HTML to display the results of a text file search query. On the previous page, there's a set of forms for a license plate number, start date, and end date. In theory, if the text file contains the license plate within the listed dates, it will show what time, date, and location all of them are shown in an unordered list. The code create the list without items initially, regardless of whether or not there's any matches. If there's matches, it creates a list item for each match. If not, it creates a single list item that says no matches were found.

Currently, however, it's trying to do both if there's no matches. If there's no number matching in the database, it'll create a mostly blank line for the "match," then display the message that there was no matches.

Here's an example of the current, wrong output:

Query results for :

    , : .

    There are no plates found matching the query.

Here's the code that's creating this. I've looked it over for an hour now and can't figure out why it's doing that.

<!DOCTYPE html>
<html>
<head>
    <meta charset = "utf-8" />
    <title>Query</title>
    <link rel="Stylesheet" media="all" href="styles.css" />
</head>

<body>
    <div class="match">
    <h1>Query results for <?= $wantedplate ?>: </h1> 
    <ul>
<?php 
    $wantedplate = $_GET["plate"];  
$data = fopen("stored.txt", "r");
$cline = fgets($data);
$match_check = 0;
list($cplate,$cdate,$ctime,$place) = explode(",",$cline);
while ( !feof($data) ) {
    list($cplate,$csubject,$cdate,$ctime,$cplace) = explode(",",$cline);
    if ($cplate == $wantedplate) {
        $match_check += 1;
?>
    <li> <?= $cdate ?>, <?= $ctime ?>: <?= $cplace ?>.</li>
<?php 
    ;
    $cline = fgets($data); }
    else {$cline = fgets($data); } 
    }
if ( $match_check == 0 ) { ?>
<li> There are no plates found matching the query. </li> 
<?php ; } ?>
</ul>
</div>
</body>
</html>

Any help that could be provided would be greatly appreciated. I've been staring at this for an hour now and still can't figured out why it's doing that. Thanks in advance for the assistance.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 ogg dd trandata 报错
    • ¥15 高缺失率数据如何选择填充方式
    • ¥50 potsgresql15备份问题
    • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
    • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
    • ¥60 pb数据库修改与连接
    • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
    • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
    • ¥20 神经网络Sequential name=sequential, built=False
    • ¥16 Qphython 用xlrd读取excel报错