I'm trying to make some custom feed with posts of image and titles and currently I'm doing it for mobile. I'm using PHP for webservice.
When using pagination how do you download posts from web? Do you send some page parameter to webservice or is there some other way?
So something like this:
http://www.mywebpage.com/?command=stream&page=0
and then just increment page that is private variable in-app and autoincremented before every new request? Or this is done in a different way?
Thanks.
Yes you are on the right track. The usual practice is to send a currentOffset, or a page number parameter (if your entries per page is constant).
I am assuming you want to display the feed in a UITableView, and lazy-load more entries (the next page of entries) when the user scrolls to the bottom of the list. You can implement the pagination logic yourself by implementing scrollViewDidScroll: to detect that you have hit the bottom of the list, but I find NMPaginator particularly helpful for this purpose.
Related
I have sort of design problem with my site. Here's the introduction:
I have a simple, dynamic page which contains a videoplayer and next to it a bunch of videos to play. Under the videoplayer there's a comment section that is powered with jquery form plugin because naturally I don't want the page to refresh and reset the video if someone enters a comment while watching.
So, the page fetches the video ID to play via a $_GET variable and then gets another 10 or so video links based on the ID from MySQL database and plays the first one and lists the rest as links next to the player.
The comment system is simple. It fetches all the comments from MySQL table having the same ID as the video playing and lists them via the jquery form plugin mentioned before. Upon entering a new comment it adds the comment to the table again by targeting the same ID.
Since the ajax form plugin fetches the comments from external PHP files containing the comment showing/adding code - I have to use a $_SESSION variable to pass the info from the main page to those files.
And here's the problem:
Everything works as I expected when a client browses the page normally.. but when he decides to open another video to a new tab - the comment system breaks down.
So what happens is that I pass the video ID from the main page's $_GET variable to a $_SESSION variable and use it to let the external show/add-comments-PHP-files know which comments to show. This works fine when a client is using only one tab but when he opens another video in a new tab the $_SESSION variable of course updates to match the new tab's currently playing video's comments and since this variable is same in both tabs - the original tab now points wrongly to the new tab's comments.
So.. to hopefully clarify a bit:
browser tab 1:
$_SESSION['now_playing'] = video 1
[..client opens another video into a 2nd tab]
browser tab 2:
$_SESSION['now_playing'] = video 2
..and from this point on the tab 1's comments are of course the same
as tab 2's.
Would there be any tricks to start a new session upon a new tab creation or something like that? I'm rather new to all this so there might be obviously silly involved.. any pointers how to get this fixed would be greatly appreciated - even if it's a better way to implement the commenting - adding comments without a page refresh is a must tho.
Regards, kitsu
You are hitting the classic problem that the Session data is controlled by a cookie, and is therefore per browser not per screen.
One approach is to have a hidden field on the screen. When handling the get to create the screen, set this to a unique value, and use that value as a key into the session data.
Then pass the value back with the ajax requests - so each screen's requests are handled with a different part of the session data.
I have created a system using php from which we can add Status messages or you can say a kind of Microblog. So it has a database table like below :
posts_mst
------------------
post_id_pk
post_title
post_content
date_added
Now I have displayed all these posts on a page using select Query and it is displaying all the posts on a single page nicely. But now I have extended the page functionality and added a form to add these posts from same page. So that form stands on the very top of the page, and below it all the posts are getting listed.
I am storing all the posts using jquery .ajax() method so page do not load while saving any post. So now what I want to do is, when I add any posts, it should keep adding the same posts on the list in a real time, like you see in a Facebook - when someone posts on their wall, we see it loaded on the spot on our News feed. Here I want to do the same, as this page will be used by so may people and posts are displayed to everyone.
There is one way I can do this is - I can append a Div tag to the list of posts everytime a New post is added. This Div content I can get using Ajax response. But that will work for only My added post. If someone else adds the Post, I will not be knowing that.
So can anyone suggest me how I can implement this ? If there is any specific plugin used for that then let me know. :)
Thank you
The easiest way is to use a javascript setTimeout every X minutes / seconds and use ajax in the timeout function to check for new posts. You can track of what's new by storing a timestamp of the latest update in a session for example.
Note that this is periodic polling, it is not really realtime.
There are newer ways to maintain a permanent connection to the server, but that's a whole other story.
In the header of my website, I have a horizontal list of the 6 latest posts. Now I would like to add a "previous" button, which causes the content of this list to be replaced by the 6 posts before the ones that are currently displayed. The idea is that, if a user clicks "previous" often enough, he is able to thereby see all posts ever made.
Most of the tutorials for creating this always load ALL posts, and then simply stuff them into some jQuery-slider. However, since I have 100+ posts, this seems not the best approach (some users might actually never click "previous" at all so why waste resources loading them).
Could you please point me to a tutorial that explains how I can get the previous posts using php each time the "previous" button is clicked? (I'm using Wordpress btw)
The problem was solved without any tutorial, just with the help of a few stackoverflow threads. Now I have an awesome Post-Slider :)
If you rely on php for that, you'll need to refresh the page each time. I think you really want an AJAX solution.
You can build a PHP web service that
1) accepts some variable, such as the ID of the lowest post currently displayed
2) outputs XML or JSON of the six posts prior to that
Then, on your page, onclick of your previous button, send the variable, accept the response, and place each post as needed. .ajax and .load are some jQuery methods to look into
i'm having a shop system which is displaying articles using a jquery slider plugin, so there's pagination.
i'm having an item with record id 123 on "page" 3 - that item has a unique modrewrite url like www.domain.com/myitem-123.html
the problem: when displaying the article details i need to somehow store the current page of the slider plugin in order to jump back to the last page of the slider.
i wouldn't like to modify my modrewrite url as it wouldn't be unique anymore (there would be different urls for same item) - the only idea i'm having is using a php session, but i'd need to set it via ajax command on each click which doesn't seem very elegant to me ..
any suggestions?
I believe a better and easier approach is to simply store that page number in a cookie and retrieve it on the slider/listing page.
But if you want to get on with your idea and need an improvement, I'd suggest to store the page number in a global variable in JavaScript and only make that request to the server right before the user jumps to the product's page ( you actually have to do it synchronously since the user is closing the page and the request can't "sit" in the background )
window.onbeforeunload = function() {
// do your server request here to store the $_SESSION['slider_page_no']
}
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 (=