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.