jEditable, jQuery and MYSQL

I’m using jEditable and the [URL=“http://www.jquery.com”]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:

<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.

This is a PHP question, but post your save.php file.

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:


<?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


<?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)")

?>

Anyone got any idea how I can get this working? Thanks.

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’;


$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.

http://www.nick-dunn.co.uk/blog/2006/08/animating-editinplacejs-with-moofx/

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

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

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.

google for “Pear db documentation” :slight_smile:

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. :stuck_out_tongue:

You can use mysql with the code you have you just need to modify the dsn name. Documentation @ :
http://pear.php.net/manual/en/package.database.db.intro-dsn.php

You also need to install the PEAR DB package.

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.

I think www.24ways.org covered creating an “editinplace” using jQuery. You can give it a shot.

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.

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…

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.

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.