I'm using a form to perform a database search and display the result.
I don't know much about programming but I found a solution doing online searches.
It is working fine, but I would like to also display a message when there is nothing found in the database.
Just like a regular search page would output "No search results found."
Any assistance would be appreciated :)
This is my form:
<form method="post">
<div>
<div>
<input type="text" name="Referencia" style="text-align: center; margin-bottom: 5px;">
</div>
<div style="text-align: center;">
<input type="submit" name="submit" value="Suchen" >
</div>
</div>
<br/>
</form>
<?php if(isset($_POST["Referencia"])) {
global $wpdb;
$name = $_POST["Referencia"];
$resultsap = $wpdb->get_results( $wpdb->prepare( "
SELECT *
FROM test_table
WHERE Referencia = %s
", $name ) );
foreach ($resultsap as $row) {
echo '<br/>';
echo '<div style="text-align: center;">';
echo '<div>';
echo '<b>Referenz: </b>' . $row->Referencia;
echo '</div>';
echo '<div style="margin-bottom: 10px;">';
echo '<b>Stadt: </b>' . $row->City;
echo '</div>';
echo '<div>';
echo '<b>Datum: </b>' . date('d.m.Y', strtotime($row->FecServicio));
echo '</div>';
echo '<div style="font-size: 20px; font-weight: bold; margin-top: 10px;">';
echo 'Uhrzeit: ' . $row->Hora_recogida . ' Uhr';
echo '</div>';
echo '</div>';
}
}
?>
No results found
";}`
– Rifky Niyas Feb 21 '21 at 16:18