Podstrona do szukania po imieniu i nazwisku:
search.php:
<!DOCTYPE html>
body{
background-color: #222222;
font-size: 24px;
color: white;
}
<script type="text/javascript"> function read_keyboard_firstname()
{
var firstname = document.getElementById("first_name").value;
document.getElementById("firstn").innerHTML=firstname;
}
function read_keyboard_lastname()
{
var lastname = document.getElementById("last_name").value;
document.getElementById("lastn").innerHTML=lastname;
}
<?php
session_start();
require_once "include/function.php";
require_once "include/function_input.php";
require_once "include/function_people.php";
select_people( $first_name, $last_name );
?>
Plik z funkcją do wyświetlania rekordów w tabeli wygląda tak:
<?php
function select_people( $first_name, $last_name ){
require_once "connect.php";
$polaczenie = new mysqli($host, $db_user, $db_password, $db_name);
if ($polaczenie->connect_errno != 0) {
throw new Exception(mysqli_connect_errno());
} else {
$rezultat = $polaczenie->query("SELECT * FROM people WHERE first_name LIKE '$first_name%' AND last_name LIKE '$last_name%' LIMIT 5");
$ile = mysqli_num_rows($rezultat);
echo 'Znaleziono: '.$ile.' rekordów</br>'; echo '<table align="center" border="1">'; echo '<th>First name</th>'; echo '<th>Last name</th>'; echo '<th>'?><input type="text" id="first_name" name="first_name"
<?php if (isset($first_name)){ echo 'value = "'.$first_name.'"'; } ?> id="first_name" onkeypress = "read_keyboard_firstname()";/>
<?php echo '</th>'; echo '<th>'?><input type="text" id="last_name" name="last_name"
<?php if (isset($last_name)){ echo 'value = "'.$last_name.'"'; } ?> id="last_name" onkeypress = "read_keyboard_lastname();"/>
<?php echo '</th>'; echo '<th><a href="kokpit.php?id_people='. $id_people .'">Dodaj</a></th>'; '<tr>';
echo '<th><div id="firstn"></div></th>'; echo '<th><div id="lastn"></div></th>'; for ($i = 1; $i <= $ile; $i++) {
$row = mysqli_fetch_assoc($rezultat);
$id_people = $row['id_people'];
$first_name = $row['first_name'];
$last_name = $row['last_name'];
echo '<td>' . $first_name . '</td>'; echo '<td>' . $last_name . '</td>'; }
$polaczenie->close();
}
}
?>
Wada mojej strony jest to, że z opóźnieniem jednej litery wyświetla mi literę, czyli po wciśnięciu 'R' nic nie wyświetla, dopiero po wciśnięciu 'o' wyświetla mi pierwszą literę 'R itd. W tym kodzie jeszcze nie mam napisanego jak przerobić wyświetlane litery by mogły być użyte do szukania jeszcze nie szuka.