?
Solved

Change database value without page-load?

Posted on 2015-01-14
4
Medium Priority
?
150 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 111

Accepted Solution

by:
Ray Paseur earned 1400 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 600 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 111

Expert Comment

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

Featured Post

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

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

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

764 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