Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 3 of 3
  1. #1
    Senior Member Blackhawk095's Avatar
    Join Date
    May 2011
    Location
    Kentucky (USA)
    Posts
    384
    Member #
    27969
    Liked
    45 times
    Many of my current website projects require a page refresh to insert, delete, update, or retrieve new content in a database. In my future projects, I would like to implement ajax to make the site run smoother, but I can't quite figure it out.

    Assuming I'm using the class below....

    PHP Code:
    <?php
    class users
    {
        public function 
    __construct()
        {
            if(isset(
    $_POST['selectUser']))
            {
                
    $this->selectUser();
            }
     
            if(isset(
    $_POST['updateUser']))
            {
                
    $this->updateUser();
            }
     
            if(isset(
    $_POST['deleteUser']))
            {
                
    $this->deleteUser();
            }
     
            if(isset(
    $_POST['insertUser']))
            {
                
    $this->insertUser();
            }
        }
     
        public function 
    selectUser()
        {
            
    $row $db->query('SELECT * FROM users WHERE id = 1');
            return 
    $row;
        }
     
        public function 
    updateUser()
        {
            
    $db->query('UPDATE users SET username = "tom" WHERE id = 1');
            return 
    'updated';
        }
     
        public function 
    deleteUser()
        {
            
    $db->query('DELETE FROM users WHERE id = 1');
            return 
    'deleted';
        }
     
        public function 
    insertUser()
        {
            
    $db->query('INSERT INTO users (username,password) VALUES("tom","123")');
            return 
    'inserted';
        }
    }

    - How would I call each method with ajax? (using buttons, or load when page is ready)
    - How would I format and display data on the web page from a 'select' query?
    - How would I automatically refresh content in a div after new content has been inserted, updated, or deleted?
    - How would I display success or failure messages?
    - How would I show a loading icon while data is being fetched?


    Thanks in advance!
    [COLOR=rgb(0, 51, 102)]Student Web Designer[/COLOR]
    [COLOR=rgb(0, 51, 102)]If you thought something I said was helpful. LIKE IT![/COLOR]

  2.  

  3. #2
    Senior Member Webzarus's Avatar
    Join Date
    May 2011
    Location
    South Carolina Coast
    Posts
    3,322
    Member #
    27709
    Liked
    770 times
    Ajax is not a single technology, but a group of technologies. HTML and CSS can be used in combination to mark up and style information. The DOM is accessed with JavaScript to dynamically display, and allow the user to interact with, the information presented. JavaScript and the XMLHttpRequest object provide a method for exchanging data asynchronously between browser and server to avoid full page reloads
    Usually requires some sort of user interaction ( the J in AJAX stands for Javascript ), Ie. Onfocus, LostFocus, etc.

    You've mad a very BROAD request without a whole lot of detail, and each of your functions would be handled differently for different situations.

    The best use I've run across for using this is a client of mine has a really long form they use on their web site, when the user hit the submit button, it would take between 2-3 seconds to post the data to the DB.. by using AJAX, I was able to send the first 3 fields when completed to the DB when the selected the 4th field of the form, then each time they would enter more data into the form and move to the next field, i would use AJAX to do an update statement..

    When the user had filled out the entire form and hits the submit button, all of the data has already been entered, so I just send them to the thank you page...

    There are like a million "examples" out there to teach you HOW to do it, and it all depends on your skills and understanding which would be the best method for you to use.

  4. #3
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,717
    Member #
    5580
    Liked
    718 times
    Also look at Drastic Data.
    http://www.drasticdata.nl/DDHome.php?m=3

    Examples of dynamic database edit (click on pencils to edit column), scroll to bottom to add rows, etc.



Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Search tags for this page

handle database query with ajax

Click on a term to search for related topics.
All times are GMT -6. The time now is 12:38 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com