SitePoint Sponsor

User Tag List

Results 1 to 17 of 17
  1. #1
    SitePoint Member
    Join Date
    Jul 2007
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    jEditable, jQuery and MYSQL...

    I'm using jEditable and the jQuery library on my Website.

    If you don't know what it is then I'll try explain. It allows you to edit content inline, for example:

    Code:
    <div class="edit" id="one">Content</div>
    If I used that code then I could click on "Content" and then it would change to a text input field then I could change it and hit Enter and it would change.

    When you hit enter the id of the div and the content of the div is sent to a file called save.php.

    The documentation/example for jEditable uses SQL Lite / Pear DB or something, but I want to use MYSQL.

    I'd like it so for every unique id I have there is a new row in a table in the database. Say if I have one with the id of "blah" and the content is "wee" then I change the content to "woo" would it update the row instead of adding a new one?

    Any and all help is appreciated.

  2. #2
    SitePoint Guru
    Join Date
    Dec 2005
    Posts
    982
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is a PHP question, but post your save.php file.
    MySQL v5.1.58
    PHP v5.3.6

  3. #3
    SitePoint Member
    Join Date
    Jul 2007
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The original save.php file that came with jEditable is below, I tried converting it to MYSQL but my efforts proved fruitless. Here it is anyway:

    Code:
    <?php
    
    require_once 'dbConnection.php';
    
    mysql_query("CREATE TABLE config(
    id INT PRIMARY KEY, 
    token VARCHAR(64),
    value TEXT
    )")
    
    $status = $dbh->query('
    CREATE TABLE config (id INTEGER PRIMARY KEY, 
                         token VARCHAR(64),
                         value TEXT)
    ');
    
    $id = $dbh->nextId('config');
    
    $query = sprintf("INSERT INTO config (id, token, value)
                      VALUES (%d, '%s', '%s')",
                      $id, $_POST['id'], stripslashes($_POST['value']));
    
    $status = $dbh->query($query);
    
    /* sleep for a while so we can see the indicator in demo */
    usleep(2000);
    
    $renderer = $_GET['renderer'] ?  $_GET['renderer'] : $_POST['renderer'];
    if ('textile' == $renderer) {
        require_once './lib/Textile.php';
        $t = new Textile();
        print $t->TextileThis(stripslashes($_POST['value']));
    } else {
        print $_POST['value'];
    }
    
    ?>
    And dbConnection.php

    Code:
    <?php
    
    require_once 'DB.php';
    
    $dsn = array(
        'phptype'  => 'sqlite',
        'database' => '/tmp/editable.db',
        'mode'     => '0666'
    );
    
    $dbh =& DB::connect($dsn);
    
    $dbh->query("
    CREATE TABLE config (id INTEGER primary key, 
                         token VARCHAR(255),
                         value TEXT,
                         date DATETIME)
    ");
    
    mysql_query("CREATE TABLE config(
    id INT PRIMARY KEY, 
    token VARCHAR(255),
    value TEXT
    date DATETIME)")
    
    ?>

  4. #4
    SitePoint Member
    Join Date
    Jul 2007
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Anyone got any idea how I can get this working? Thanks.

  5. #5
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Having had a quick look I think you are in for a hard time.

    jEditable looks really neat, but its a plugin for jQuery. The samples are built with as you point out dependencies on other classes to manage database access etc.

    If you don't already know this jQuery package, you should first become very familiar with it. My advice is to write some simple test stuff using jQuery before launching off trying to hack around other plugins. Make sure you get into your head how Ajax works.

    If you are totally sold on jQuery then get comfortable using that package, and I am sure you will work out how to write your own application that does pretty much what jEditable does.

    If you are after an "editinplace" as it is sometimes termed then try this search

    If you are determined to see this through with jEditable then you likely need to edit the dns here:

    require_once 'DB.php';
    PHP Code:
    $dsn = array(
        
    'phptype'  => 'sqlite',
        
    'database' => '/tmp/editable.db',
        
    'mode'     => '0666'
    ); 
    So you should head off for the user manual for that PEAR package, and change those settings to suit.

    I am not familiar with it.
    Last edited by Cups; Jul 21, 2007 at 14:35. Reason: added dns entry to be changed

  6. #6
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    http://www.nick-dunn.co.uk/blog/2006...js-with-moofx/

    Heres a play on EditInPlace using the Moo.fx library. This is genius.

    I really like moo.fx JS library, really tiny.

  7. #7
    SitePoint Member
    Join Date
    Jul 2007
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks a lot for your reply, I'm using quite a few other things from jQuery so I think I want to stick with it...I'll try some of your advise but I really don't know all that much about coding at all...

    Does anyone have any more information/ can help me get it working? Thanks for your help though Cups.

  8. #8
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by Cups View Post
    So you should head off for the user manual for that PEAR package, and change those settings to suit.
    google for "Pear db documentation"

  9. #9
    SitePoint Member
    Join Date
    Jul 2007
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    To be honest I couldn't really give what library is used or anything as long as the EIP comes with php files that save the changes to a database...I like the one with Moo FX though, very pretty. :P

  10. #10
    SitePoint Evangelist
    Join Date
    Aug 2005
    Posts
    453
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can use mysql with the code you have you just need to modify the dsn name. Documentation @ :
    http://pear.php.net/manual/en/packag....intro-dsn.php

    You also need to install the PEAR DB package.
    Computers and Fire ...
    In the hands of the inexperienced or uneducated,
    the results can be disastrous.
    While the professional can tame, master even conquer.

  11. #11
    SitePoint Member
    Join Date
    Jul 2007
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm well I don't think my host wants to install it...and I prefer MYSQL 'cause the rest of the site uses it.

  12. #12
    SitePoint Evangelist
    Join Date
    Aug 2005
    Posts
    453
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Aureole View Post
    Hmm well I don't think my host wants to install it...and I prefer MYSQL 'cause the rest of the site uses it.
    You should ask your host, the package is probably already installed.
    PEAR DB is an object oriented data base access package that comes from the Php Extension and Application Repository. You can access many different Data bases, including MySQL by changing parameters in the dsn.
    Computers and Fire ...
    In the hands of the inexperienced or uneducated,
    the results can be disastrous.
    While the professional can tame, master even conquer.

  13. #13
    SitePoint Guru
    Join Date
    Dec 2005
    Posts
    982
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think www.24ways.org covered creating an "editinplace" using jQuery. You can give it a shot.
    MySQL v5.1.58
    PHP v5.3.6

  14. #14
    SitePoint Member
    Join Date
    Jul 2007
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I took a look at the thing at www.24ways.org but they don't tell you how to save the changes so it doesn't really help...

    I don't care if I use Prototype or Scripatculous or jQuery or Moo.FX or whatever as long as I have a way to save the changes to a Database...

    Can anyone help me out please, I really need this...thanks.

  15. #15
    SitePoint Member
    Join Date
    Jul 2007
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I just found this which to me looks amazing...but it has no saving routines...if anyone could help me out to get it so it can save to a mysql database then I would probably donate via paypal or something and would be eternally grateful...

  16. #16
    SitePoint Zealot Dachande663's Avatar
    Join Date
    Feb 2005
    Location
    Birmingham, UK
    Posts
    151
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've been trying JEditable as well and if you're using the same version as me you don't actually have to use that save.php script, you can tell the JS to use any php page and put your own code in it. That way you can just do a basic mysql update.

  17. #17
    SitePoint Member
    Join Date
    Jul 2007
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I know you can use your own PHP script but I don't know how to make it otherwise I would do that but now that I have found this I would much prefer to use it...over anything - it's amazing.


Bookmarks

Posting Permissions

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