Solved

Change database value without page-load?

Posted on 2015-01-14
4
147 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 109

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 109

Expert Comment

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

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to combine and minify CSS and JS files 5 17
return false must be hit after calling certain command 10 32
issue with DB import 1 17
Javascript 2 21
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

856 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