Heads up before reading. I'm totally new in html and so, so please be patient. I have the following html code and two javascript functions.
<HTML> <HEAD> ..... </HEAD>
<BODY>
<CENTER>
<form id="keyForm">
Όνομα/Επώνυμο: <input type="text" name="keyword"><br><br>
<input type="button" onClick="resetFunction()" value="Επαναφορά">
<input type="button" onClick="my_search(this.form.keyword.value)" value="Αναζήτηση">
</form>
<p id="results"></p>
</CENTER>
<script>
function resetFunction() {
document.getElementById("results").innerHTML = "";
document.getElementById("keyForm").reset();
}
</script>
<script>
function my_search(kw) {
document.getElementById("results").innerHTML = (
<table border="1" style="width:500px">
<tr>
<td>ID</td>
<td>Επίθετο</td>
<td>Όνομα</td>
<td>Ημερομηνία πρόσληψης</td>
<td>Τμήμα</td>
</tr>
</table> );
}
</script>
</BODY>
</HTML>
I want the "results" to be be table that is described in function "my_search" extended by the actual results produced by the following php code.
<?php
header("content-type: text/html;charset=utf-8");
$link = mysqli_connect("127.0.0.1","root", "tralalalalala", "mycompany");
if (!$link) {
printf("Connect failed: %s\n",
mysqli_connect_error());
exit();
}
//printf("Host information: %s<br>",
//mysqli_get_host_info($link));
$key = $_POST['keyword']; //Keyword in initialized in html
//echo $key; echo "<br>";
$stmt = mysqli_prepare($link, "
select e.emp_id, e.first_name, e.last_name, e.hire_date, d.dept_name
from employee e, department d
where e.dept_id = d.dept_id and (e.first_name like ? or e.last_name like ?)");
$likeKey = "%{$key}%";
mysqli_stmt_bind_param($stmt, "ss", $likeKey, $likeKey);
mysqli_stmt_execute($stmt);
mysqli_stmt_bind_result($stmt, $id, $f_name, $l_name, $hire_date, $d_name);
$stmt->store_result();
$rows = $stmt->num_rows;
if ($rows)
printf("Βρέθηκαν %d αποτελέσματα<br>", $rows);
else
printf("Δε βρέθηκαν αποτελέσματα για τη λέξη-κλειδί \"%s\" <br>", $key);
for ($i = 0; $i<$rows; $i++){
mysqli_stmt_fetch($stmt);
printf("%d %s %s %s %s <br>", $id, $f_name, $l_name, $hire_date, $d_name);
}
mysqli_stmt_close($stmt);
mysqli_close($link);
?>
In the end I wanna have something like this
It's Greek but I think you can handle it ;) Thank you for your replies :)