我是我在学校的第一个编码项目。我有一个任务要检查,两个条件是否为真,如果是,我必须计算出现次数。我现在真的很困惑,我会很感激每一个有用的答案。
所以这是代码的一部分:
$verbindung = mysqli_connect($server, $user, $pass, $database)
or die ($meldung);
$driverID = $_POST['fahrer'];
$datum_von = $_POST['date_von'];
//Change Date Format
$datum_von_new = date_format(new DateTime($datum_von), 'Y-m-d');
$datum_bis = $_POST['date_bis'];
//Change Date Format
$datum_bis_new = date_format(new DateTime($datum_bis), 'Y-m-d');
$sql = "SELECT drivers.forename, drivers.surname, results.positionOrder, races.name, races.date ";
$sql.= "FROM drivers ";
$sql.= "INNER JOIN results ON drivers.driverId = results.driverId ";
$sql.= "INNER JOIN races ON results.raceId = races.raceId ";
$sql.= "WHERE drivers.driverId = '$driverID' ";
$sql.= "AND races.date BETWEEN '$datum_von_new' ";
$sql.= "AND '$datum_bis_new' ";
$sql.= "AND results.positionOrder <= 10;"
<table class="table table-striped">
<thead class="thead-dark">
<tr>
<th scope="col">Fahrername</th>
<th scope="col">Streckenname</th>
<th scope="col">Datum</th>
<th scope="col">Platzierung</th>
<th scope="col">Häufigkeit</th>
</tr>
</thead>
$ergebnis = mysqli_query($verbindung, $sql);
$countPosition = 0
if ($ergebnis != False) {
while($zeile = mysqli_fetch_array($ergebnis)) {
echo "<tr>";
echo "<td>" . $zeile['forename'] . ' ' . $zeile['surname'] . "</td>";
echo "<td>" . $zeile['name'] . "</td>";
echo "<td>" . $zeile['date'] . "</td>";
echo "<td>" . $zeile['positionOrder'] . "</td>";
for($i = 0; $i<=sizeof($zeile); $i++) {
for($j = 0; $j <= sizeof ($zeile); $j++) {
if($zeile['name'][$i] == $zeile['name'][$j] &&
$zeile['positionOrder'][$i] == $zeile['positionOrder'][$j]) {
$countPosition += 1;
echo "<td>" . $countPosition . "</td>";
}
}
}
echo "</tr>";
} else {
echo mysqli_error($verbindung);
}
$result = mysqli_close($verbindung);
所以我的目标是检查第 1 行中的名称是否等于第 2 行中的名称,以及第 1 行中的 positionOrder 是否等于第 2 行中的 posisitionOrder。如果是,请计算这是正确的次数。帮助表示赞赏。谢谢!