I have a PHP page which displays n number of records in form of table from database(till here pagination works fine). Using a search field i am triggering another query, which displays the results in 2 pages. The first page shows the result fine, but when i click on the 2nd page link, it displays the result from the initial query.
any suggestions would help me to identify the actual issue that is causing this.
Thanks!
As a was stuck with same issue earlier.
The solution is to pass searching input value along pagination parameters.
In your case pagination just take it's parameter and performs its working by excluding searching query.
So just passing searching input value(Query) you will get proper result.
Related
I have a filter for example example.com/mypage?page=2&name=Alex
And I have a lot of data with this name and the limit on pagination is 15. My problem is this. When I make the filter everything it's ok because when I press a button i'm sending with GET the values, and the first page it looks good, but when I press for the page 2 on laravel pagination the parameters are removed and it looks like example.com/mypage?page=2. What can I do?
You can just append additional parameters as described here
$users->appends(['name' => 'Alex'])->links();
This is my first time posting in stackoverflow so please tell me if I need to add more information!
I am attempting to take a value from the mysql database and add 1 to it when the page loads. The user clicks on the link on the first page and when the linked page is loading and the php code below runs it adds 1 to the value of the column Clickcount in the entry with the Name value TheButton in the table "lots".
The following code worked when I ran it through Dreamweaver with WAMP:
<?php
$con=mysqli_connect("localhost","root","qwerty71","Lots");
mysqli_query($con,"UPDATE Lots SET Clickcount=Clickcount+1
WHERE Name='TheButton'");
$result=mysqli_query($con,"SELECT * FROM Lots where Name='TheButton'");
while($row= mysqli_fetch_array($result))
{
echo $row['Clickcount'];
}
mysqli_close($con);
?>
But when I put the same code into my website (only changing the values after the mysqli_connect to connect to the database) it doesn't work. The echo at the bottom is to show the value after it is changed, I have the same echo on the first page to show the value before it is edited by the second page. I set the value to zero in the database before I loaded the first page or clicked the link. The first page shows the value at zero, and after clicking the link the second page changes the value and displays a 1. When I try to click back to the first page it shows a 1 instead of a zero, but then both pages continue to display 1s instead of adding 1 every time the link is clicked.
I have tried multiple ways of changing the code after the SET Clickcount=
Including attempting to add a variable before query that I set equal to the Clickcount value and trying to add 1 to that.
Is there an error in my code that would prevent it from working properly, or is there an alternate way to set this up to get the desired result?
Re-explanation for clarity:
My table is as follows:
Name Clickcount
TheButton 0
I am trying to increase the value under "clickcount" by 1 every time a page is loaded. My code (posted above) functioned properly when run on a local server, I changed the parameters to match my server online.
The homepage has a portion of the code above to show the value of the Clickcount column and a link to the second page, where the code above is located.
The code functioned once, changing the value from zero to one, but then ceased to work on consecutive attempts.
Is there an error in my code? Or is there a better way to accomplish the task of increasing the value?
Further update:
The code seems to be working once every 5-10 minutes. I have left it as it is above, and it was not doing this before. I do not know what changed.
In addition, every few times that it does work, I get the result of receiving two different values when calling the following portion of the code on two separate pages:
$result=mysqli_query($con,"SELECT * FROM Lots where Name='TheButton'");
while($row= mysqli_fetch_array($result))
{
echo $row['Clickcount'];
}
mysqli_close($con);
This code is on the homepage, where it sometimes results in a number one less than what the value is recorded to be in the mysql table. Where on the page with the complete code listed above, it always shows the same value as in the table.
In my continuing effort to figure this out, I have removed all of the files off of the server where my site is hosted, and started again from scratch. After re-writing all of the code for the two pages, creating a new table in a new database, and implementing the code above on the second page, the error remains.
I have also just now signed up for a new hosting service to see if it was the server that was causing the problem. Sadly, that was not it. Does anyone have a suggestion for a solution?
Look to this points:
Copy your query and put in the database. It works?
In the end of your update line, put or die(mysqli_error($con)). If show errors, look to error;
There value 'TheButton' in the column Name in your remote table?
Try change in the clause where in update query, Name='TheButton' to Name LIKE 'TheButton'
Always throw messages errors in your codes. Is the best way to find mistakes. ;)
The page was loading a cached version instead of loading from the site itself. I added some coding to the header to remove the caching, this fixed the problem.
I'm just looking for some advice in this post.
I am currently using pagination via a $_GET variable in the url. However I am not paginating by first calculating a count and then using a LIMIT clause. Instead I am retrieving all values to paginate, then placing them in an array which is then sliced, so the first 10 items of the array are displayed on the first page, and the next 10 on the second page, etc. There is a reason for this madness.
However, this results in the entire query running every time a user clicks a different page number.
Is it at all possible to instead use jQuery/AJAX, so that I can run the query once, then simply cycle through the array without having to reload the page?
Any help would be greatly appreciated.
Thanks
Yeah if you have to get everything out in your query anyway you might as well divide everything up into pages in one go and put them on your page ready to be hidden/shown. Then your page links/buttons will just need to hide the current page and show the page clicked. Shouldn't be too much work.
I am a php programmer.When a page gets loaded some records are shown from a table(in a tabular format on the php page) , on the page there are html submit buttons corresponding to whose post some other values are to be shown.
The problem is, the other values are shown along with the values which are shown when the page first loads. I want to show fresh set of values , without the default values which are shown when the page first loads.
It has to be mentioned that the default page load values which are fetched from the table is not done corresponding to any isset($_POST) unlike the other fresh values.
can you help me out?
Try using some random numbers in the query or other patterns in the query so that you get records afresh than getting the same records every time you visit the page.
Hope my understanding is right.
I am not sure the correct terminology for the process that I am trying to describe. I don't even know which platform is underlying the technique. If you understand my description, please give the link to the site(s) and or the keyword name of the process. I think it is done by AJAX, but I am not certain. I use php as the backend code, I just need to find a way to dynamically display the results. Please give suggestions. I forgot the name of the sites that use this, and my link history expired.
TIA
Description:
The page would have a search form and options. After the user submits, the search is initiated, and the results appear inside the dedicated result area. The page does not refresh, just the info inside the result area.
The display area will show 20 (or whatever) results (lines). There will be next, and previous buttons. If you hit next, the next set of results will display.
I am writing a code that generates 20 results for each display. There is no set number of results, so the results might have a start/first page, but do not have an end page.
Each time the user hits 'next', the program would generate/load new results. It would also store previous results, so that when a user hits 'prev', the previous results can instantly come up.
What techniques/program are theses?
Having recently handled pagination with Code Igniter (php framework), the following links might help you and anyone else out:
http://tympanus.net/jPaginate/
http://codeigniter.com/forums/viewthread/93045/
Usability is important and AJAX pagination introduces some important questions that need addressing regarding pagination, the following article will give some usability guidelines for displaying results in a table:
http://thedesignvanguard.com/crud-r-for-read
Code Igniter Prototype Framework Ajax Pagination:
http://codeigniter.com/wiki/AJAX_Pagination_with_CI_Pagination_Library/
Since we're using jQuery, we chose the following, Codeigniter jQuery framework for AJAX pagination
http://tohin.wordpress.com/2008/08/12/codeigniter-ajax-pagination/
http://tohin.wordpress.com/2008/10/07/codeigniter-ajax-pagination-exampleguideline/
It is not AJAX for sure.
Nobody uses AJAX for the pagination.
And there are about zillion pagination examples over internet
The only thing is never described in articles is how to persist search options for the other pages.
But it's simple enough: http_build_query() can help you
You need to have a GET/POST form submitted via AJAX which contains the fields in the search term and page number.
If you are going to set the page size to 20 results, page_num=4 will show results from 61-80 results.
Usually search results are GET instead of POST (Ex: See Google search results ) along with the page_number as another attribute and value.
#IVAN .. good to know that the library came helpful..
About that searching option; check the recent commit in github
http://github.com/neotohin/CodeIgniter-Ajax-pagination-Library there is an additional parameter added for searching.
I think the simple code in readme is enough for understanding the mechanism.
You could use datatables
https://datatables.net/
https://datatables.net/examples/data_sources/server_side.html
With this plugin using jquery also you could use server sided page request , you just have to handle the plugin post using Ajax.
post automatically sends row , page offset column, search criteria you just have to provide the json encode return
and the plugin automatically has library in featuring pagination, search sort number of rows per page and the table formatting.
Needed are jquery, and the plugin css and js for this to work
let me know if you understood my explanation.
thanks (=