jQuery list that saves user selection (like a cart) - php

I'm working on a travel website. I'm looking for a function that allows my users to click a hotel and save their selection to a "list" on the sidebar.
I want it to function like a cart so that the list never erases and so that you can see the selection until you are ready to print everything out.
Any help/suggestions are appreciated.
Thanks!

If your users are going to be clicking around to a lot of pages, it will be a real challenge to keep sending this growing list around from page to page on the client side. I would recommend that you consider a different approach. One is cookies, and another is session state.
If you are using server-side code, it would help us to know what language you are using so that we can give you some more ideas.

I would suggesting using AJAX to pass the selection to the backend. If you want this to persist across multiple sessions you're going to want to save it to a database so they can come back later.
http://api.jquery.com/jQuery.ajax/

Use cookies if you don't want to use php.
http://www.w3schools.com/js/js_cookies.asp
has a good example of how to use cookies in javascript.

I recommend using "My favourite posts" wordpress plugin for this kind of job.

Related

How to add two pages together

I was wondering how can I add two different pages together in php. For example, I would like to have the time variable on about.php and contact.php page and if I change the time from one page, it will affect the other page at the same time. Is it possible to do this from the mysql database?
Thanks
You may use a session for making your pages stateful if that is what you are asking. In my opinion using database call for this purpose would be an overkill. Try setting a session variable for the domain and you may call that variable from any page of that domain.
Please visit these links for further reference for session variables:
PHP Sessions across subpages of same domain
If using javascript/jquery, you may also have a look at this:
One Cookie - Multiple Pages
i think you can do that use require('filename') in PHP, that function/built in make yout get variabel, class etc from another file like you want to do .
that the reference : http://php.net/manual/en/function.require.php
Hope can help
Here is my response.
The qusetion is, Do you want the time update to be real-time event or not.
Real-Time Event:
If you want the update to be real-time(Ie The Page will not refresh or reloads upon the event updates) then you better do it with nodejs and websocket. The most common websocket
is Socket.Io.
Not-Realtime Event
If its not gonna be real-time. You can then use php. You can write an update code in any of the page. You will then also write a code to query the time from the database. Embed the query codes on both pages so that each time the page reloads or refreshes, the time will be fetched from the database and it will work fine. Your best bet will be to combine php with ajax. Thanks You

Update GUI when data source is updated

I want to update my PHP GUI view when my data source is updated(data source can be a database). I'm having a hard time understanding how I can do this without reloading the whole view for the user.
What I try to achieve is:
Users view are shown, from an handheld device call a script on the site and the script updates a data source, when data source is updated, update the users view with this updated data without reloading.
Is this possible with PHP/JS and how would I achieve this? I do not need any code but more step by step explanation and perhaps what technology to use.
Appreciate any suggestion that leads me forward with this problem.
Best regards,
Gabriel Paulsson
Use ajax for refreshing data when any event happens. The page will not reload by using ajax. It is very simple to use ajax. Googel, gmail and many other use such ajax. Learn in ten minutes form w3school http://www.w3schools.com/ajax/default.asp
It should be possible to do it just with php, telling the page to update itself at a certain interval.
The way I would do it, is to use javascript with ajax and a timed event. The event fires of an ajax call to the server, the server returns any new information.
If you are new to ajax, you probably want to use a library to make things a bit easier to handle. My personal favourite is prototype.js, although at the moment that seems to be a bit "on the way out" and eg jquery may be a better alternative.

How would I create a wish list?

I'm making a website which displays a big list of items, similar to how eBay lists items. For each item there is a button that allows you to save it to your "wish list," and a link that brings you to a page that lists all the items on your wishlist.
How would I go about implementing this? I am currently using Javascript cookies and passing the values in the URL for PHP to pick up and display the wish-listed items. It feels like there must be an easier/better way to do this though. Any suggestions?
The best way to store the wish list is the database only. You can do that by some ajax.
Or if you dont want to store in database then store it in session. I personally feels that the session will be the best thing.
I am not sure what you mean with I was using javascript cookies, passing the values in the url, but unless you want to save the wish-list to Db, a cookie will be a good way to go.
Another way would be to execute an ajax-request to the server when you add something to the list, having the server-side code saving the item for you in a session. Then session could then be read when you want to display the list.
Also, HTML5 gives you local storage. Maybe too limited browser support for you, but worth checking out.

What technology use to make a webpage to update in real time?

I want to make a webpage where an user can add the title from a book he has read. These changes are reflected in real time on a list that contains all books he has introduced on the database, without the need to press any "reload" button. By example: there is no need to refresh (F5) the page to see the last book added.
I don't know if I can do this in PHP or in any other language, so I would like to know which is the best suited for something like this.
Thank you.
I think you are looking for Ajax. Would be able to asynchronously update the section of the page (the post in this case) without the need for page refresh.
You will want to do this with javascript, using the onchange event, and for a discussion on this you can look at: Call Javascript onchange event by programatically changing textbox value.
Basically, you react to the data being changed, then just send it immediately over using ajax to the server, but, you need to be aware of two things.
First, how will you handle errors, such as there is no book with that title, or the length is too long. I tend to put the error message in or by the place where they had the bad data.
The other is that you need to pass back the id when the data was inserted, so that when they change it again you can just do an update, so you will need to store that. I tend to put the database id I need in the element id, but you can keep it in an array in javascript, since it will maintain state for you.

PHP save a page then redirect to previous page(ajax)

I would like to ask for how to redirect to previous page (ajax paging).
Example,
Let's say currently I am in page 5, then I click on one record, after I edit it, I would like to go back to that page 5 not page 1.
The problem is my paging is using ajax,
http://domain/photo/#5
I try to use $_SERVER[http_referer], but I only get http://domain/photo , I not able to get # and the value.
What is the best way to redirect back to the previous paging. My last choice is using $_SESSION. Hope I can get better answer here.
Thx.
Like Lauri says, you need to manage this at the client-side using Javascript. Basically you need to implement some sort of client-side browser history. Just look at how Facebook loads in photos, but still lets you use the back button.
There are various libraries available to help you:
JS History Frameworks

Categories