Assuming in PHP
file there're :
function printAllRows(){
for( everyrows in db){
echo "<tr>";
echo "<td> $_POST['..'] <td>";
echo "<td> $_POST['..'] <td>";
echo "<tr>";
}
}
function printSpecifRows($keyword){
.....
}
// When the page loads for the first time
if ($db->preRow() >0){ // count rows in DB , if there already show them as table
printAllRows();
}
At the same time , there is
<input type="text" name="keywoard" />
<input type="submit" name="find" value="search" />
If the user enter the keyword press the button , then just show the rows match the keyword!
so :
if( $_POST["find"]){
?>
<script>
// first clear the current DOM table
document.getElementById("myTable").innerHTML="";
</script>
<?php
// then print again! according to printSpecifRows($keyword)
function printSpecifRows($keyword){
.....
}}
But the problem here is that JS
is rendered first before PHP
, so printSpecifRows($keyword)
won't never be reached , any idea. I really appreciate your help. Thanks.
You are massively over-complicating things. Get rid of the <script>
entirely. There is no need or point in involving JS here.
Just change the PHP so it doesn't output all the data in the first place if you don't want it on the page.
if ($_POST["find"]){
printSpecifRows($_POST["find"]);
} else {
printAllRows();
}