Solved

Change database value without page-load?

Posted on 2015-01-14
4
143 Views
Last Modified: 2015-01-19
Hi,

I got a page which contain a lot of rows from a table.
The db-table got a "locked" column (ENUM "0","1").

I display a lock/unlock image to the user, based on the value of this column.
Is it possible to change db value and replace image without a page-load?
0
Comment
Question by:kgp43
  • 2
4 Comments
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 350 total points
ID: 40548688
The "without a page load" part seems to imply that you would make an AJAX request.  The short answer is "yes, you can do that."  There is an article here that gives the design pattern of a PHP / jQuery AJAX implementation.   It shows how to get around the "page load" issues and still accomplish back-and-forth communication with the server via the standard request/response.
http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Jquery/A_10712-The-Hello-World-Exercise-with-jQuery-and-PHP.html

More about the nature of HTTP:
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/A_11271-Understanding-Client-Server-Protocols-and-Web-Applications.html
0
 
LVL 2

Assisted Solution

by:Elxn
Elxn earned 150 total points
ID: 40551404
Got a version of this working on my site.  See it here: http://girlzunderground.com/ee.html

Do you need the code explained to you?

You'll need to change all the image names in the javascript code and you'll also need to change what page the ajax call is made to.

Just change the actual image name, you shouldn't have to worry about the path as long as the two images (lock.png / unlock.png) are in the same folder.

Also, you see the function accepts the parameter "id"; this is posted to the page as well--you might want to put the id of the record in the onclick event in the image tag (right now its 1, 2, or 3) and this value will get sent to your page as well.  THought you might want that.
0
 

Author Closing Comment

by:kgp43
ID: 40557786
Thank's alot guys, exactly what I was looking for :)
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 40557803
Thanks for the points and best of luck with your project, ~Ray
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now