Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function getBooks($start = 0, $limit = 2, $order = "ASC")
- {
- $sql_start = $start * $limit;
- $sql_limit = $limit;
- $sql_order_by = $order;
- $query = "SELECT Library.nameOfBook, userBook.book_id, userBook.user_id FROM loginUser JOIN userBook JOIN Library ON userBook.user_id = loginUser.id AND userBook.book_id = Library.id WHERE loginUser.username=:username ORDER BY Library.nameOfBook $sql_order_by LIMIT $sql_start, $sql_limit";
- $statment = $this->db->prepare($query);
- $statment->execute([
- ':username' => $this->username
- ]);
- $result = $statment->fetchAll();
- echo "<table id='myTable' border='1'>
- <tr>
- <th><a id='sorter' href='#'>Books</a></th>
- <th>Action</th>
- </tr>";
- foreach($result as $row){
- echo "<tr>";
- echo "<td>" . $row['nameOfBook'] . "</td>";
- echo "<td>" ."<input type='submit' id='delete".$row['book_id']."-".$row['user_id']."' onclick='deleteBook(this)' name='delete' value='Delete'>" . "</td>";
- echo "</tr>";
- }
- echo "</table>";
- echo "";
- return count($result);
- }
- <script>
- $(document).ready(function() {
- $( "#sorter" ).click(function() {
- var order_by_value = $('input[name="order_by"]').val();
- if(order_by_value == "ASC"){
- $('input[name="order_by"]').val("DESC");
- }
- else {
- $('input[name="order_by"]').val("ASC");
- }
- $('input[name="current"]').trigger('click');
- });
- });
- </script>
- <script>
- $(document).ready(function() {
- $( "#sorter" ).click(function() {
- var order_by_value = $('input[name="order_by"]').val();
- $.ajax({
- type: 'GET',
- url: 'the url link ',
- data: {
- 'order_by_value': order_by_value
- },
- success: function (res) {
- if(res == "ASC"){
- $('input[name="order_by"]').val("ASC");
- }
- else {
- $('input[name="order_by"]').val("DSC");
- }
- $('input[name="current"]').trigger('click');
- });
- }
- });
- </script>
- $.ajax({
- type: 'GET',
- url: 'your_page_link.php',//this will be url of your backend page
- data: {
- 'name':name
- 'email':email
- },// if you are using form then just use .serialize() to submit the form instead of preparing data like this use $("#form_id").serialize()
- success: function (msg) {
- resp = msg;
- }
- }).done(function(){
- if(resp == your_expected_response){
- window.location.href = "http://stackoverflow.com";
- }else{
- //your error handler
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement