Nach einer vorherigen Frage habe ich meine Form, die aber im Moment ist, wann immer ich versucht habe, ein Schlüsselwort einzugeben, wird die ganze Tabelle nur angezeigt. Gibt es eine Möglichkeit, nur Übereinstimmungen anzuzeigen? Zum Beispiel, wenn ich Wohnungsleeds suchte. Es würde die ganze Reihe in einer Tabelle zeigen?Sucheingabe zeigt keine exakte Übereinstimmung von csv, wenn gesucht
Gehäuse Leeds, Yorkshire LL, 3,2013,221,235
index.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<form action="search.php" method="get">
<label>
Search
<input type="text" name="search" autocomplete="off">
</label>
<input type="submit" name="Search">
</form>
</body>
</html>
search.php
Hilfe von einem anderen Benutzer:
search.php
<?php
$search = isset($_GET['search']) ? (int) trim($_GET['search']) : null;
$search = isset($_GET['search']) ? trim($_GET['search']) : null;
$search = isset($_GET['search']) ? (int) trim($_GET['search']) : null;
$search = isset($_GET['search']) ? trim($_GET['search']) : null;
$search = isset($_GET['search']) ? trim($_GET['search']) : null;
define('CSV_INDEX_LANDLORD', 0);
define('CSV_INDEX_LANDLORD_GROUP', 1);
define('CSV_INDEX_QUARTER', 2);
define('CSV_INDEX_YEAR', 3);
define('CSV_INDEX_ESTIMATED_PROJECT_COST', 4);
define('CSV_INDEX_ACTUAL_PROJECT_COST', 5);
$row = 1;
$output = [];
if (($handle = fopen("data.csv", "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$num = count($data);
$row++;
// if the user tried to search on year and it doesn't match, continue skips to the next row
// casting ensures we compare integers with integers
if (!empty($search) && stripos($data[CSV_INDEX_LANDLORD], $search) !== false) {
continue;
}
if (!empty($search) && stripos($data[CSV_INDEX_LANDLORD_GROUP], $search) !== false) {
continue;
}
if (!empty($search) && stripos($data[CSV_INDEX_QUARTER], $search) !== false) {
continue;
}
if (!empty($search) && stripos($data[CSV_INDEX_ESTIMATED_PROJECT_COST], $search) !== false) {
continue;
}
if (!empty($search) && stripos($data[CSV_INDEX_ACTUAL_PROJECT_COST], $search) !== false) {
continue;
}
$output[] = $data;
}
fclose($handle);
}
?>
<?php if (!empty($output)): ?>
<table>
<tr>
<th><strong>Landlord</strong></th>
<th><strong>Landlord Group</strong></th>
<th><strong>Quarter</strong></th>
<th><strong>Year</strong></th>
<th><strong>Estimated Project Costs</strong></th>
<th><strong>Actual Project Cost</strong>
<tr>
<?php foreach ($output as $row): ?>
<tr>
<td><?=$row[0]?></td>
<td><?=$row[1]?></td>
<td><?=$row[2]?></td>
<td><?=$row[3]?></td>
<td><?=$row[4]?></td>
<td><?=$row[5]?></td>
</tr>
<?php endforeach; ?>
</table>
<?php endif; ?>
Ich bemühe mich, es zur Arbeit zu bringen, so dass, wenn ich entweder einen Vermieter oder eine Vermietergruppe betrete, Daten darüber in der Tabelle angezeigt werden. Unten sehen Sie eine Reihe von CSV-Daten. Die fett gedruckten sind die Überschriften.
**Landlord,Landlord group,Quarter,Year,Estimated project costs (000s),Actual project cost (000s)**
Housing Leeds,Yorkshire LL,3,2013,221,235
die '' in Ihrem Formular hat keinen Namen. Es muss eine in $ _GET ['inputname'] 'enthalten sein. – Jeff
Woher soll '$ _GET ['Vermieter']' und alle anderen kommen? – Jeff
Das Fett in der Frage ist die Überschriften im csv, also habe ich angenommen, dass dies funktionieren würde, wenn ich einen Namen der Suche hinzufüge. Wie würde ich das schaffen, weil ich viele Köpfe habe? –