Solved

Change database value without page-load?

Posted on 2015-01-14
4
148 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 110

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 110

Expert Comment

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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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 …
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
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 how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

749 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