Reputation: 79
I have a table that is displaying all the data i query from the database, here i want to add a search box ontop of it to help me sort or find the data i want. I Wish not to refresh the page but directly change the data display, Only thing i can think is to use Jquery but i remember you can't change the PHP Query string with javascript. How do i archive this? like using onchange condition of search box,and search data shown on the table.
sql='SELECT * FROM XXX'
$row=mysqli_fetch_array($result);
<form>
<input type='text' name='Search'/>
</form>
<table>
<tr><td><?php echo $row['Name'] ?></td><td><?php echo $row['Job'] ?></td></tr>
etc.....
</table>
Upvotes: 0
Views: 237
Reputation: 6572
PHP just runs once and it's done. This means, you will need to write some Javascript that sends a new request and returns the result. This is what most here meant by AJAX.
You could set up a new PHP file where you take the query as a parameter and return the data as JSON. DataTables, which @Cashbee suggested could then take this data and present it.
Depending on who will be able to access this website, you should also think about security ... Is it Ok, if anyone, having access to this site can run whatever query he likes?
Just a sitenote: You are not by any chance looking for a tool like phpMyAdmin or Adminer?
Or are you looking for a tool where you can see the result as you type the query? Something as a dry-run for insert
, update
or delete
queries maybe in addition ..? If that is your idea, maybe transactions is something you'd like to look into.
NOTE: Hey ... this last paragraph would make a very good program for beginners to show them what databases do before they do it ...
Upvotes: 0
Reputation: 5766
I use DataTables for these kind of things. It does exactly what you are looking for. You might want to check it out, its well documented
Upvotes: 1