How to use jeditable with mysql ?

How to use jeditable with mysql ?

mickeymicmickeymic Posts: 23Questions: 0Answers: 0
edited September 2009 in General
Hello,

Sorry for my english.

I use DataTables and mysql, and I want to use Jeditable with mysql. I think that I must use editable_ajax.php, but if I see the example, there is :

[code]<?php
echo $_POST['value'].' (server updated)';
?>[/code]

I try to find solution, but I have problem.

Is it possible to have a complete example of editable_ajax.php to update mysql ?

Thanks

Replies

  • allanallan Posts: 61,627Questions: 1Answers: 10,090 Site admin
    Hi mickeymic,

    There isn't a complete example of this currently available, because obviously the sever-side process would be different for everyone! So it's left as a challenge for you the developer :-). The best way to learn these things is just to get stuck in. You will need the row ID (and possibly the column name) that you want to update - these can be passed from the client-side (a small modification is needed to the example to do this) and then all you need to do is make an UPDATE SQL call.

    Regards,
    Allan
  • mickeymicmickeymic Posts: 23Questions: 0Answers: 0
    Arf I like challenge, but I have problem

    sorry :D(

    I try to passe variable like this :

    [code]
    var oTable;

    $(document).ready(function() {
    /* Apply the jEditable handlers to the table */
    $('.center').editable( 'media/editable_ajax.php?id=<?php echo $data['id']; ?>&col=<?php echo $data['reponse_contenu_jeux_'.$d.'']?>', {
    "callback": function( sValue, y ) {
    var aPos = oTable.fnGetPosition( this );
    oTable.fnUpdate( sValue, aPos[0], aPos[1] );
    },
    "height": "14px"
    } );


    /* Init DataTables */
    oTable = $('#example').dataTable();
    } );
    [/code]

    This is my form :

    [code]










    <?php

    for ($f = 1; $f <= $nbre_champs; $f++)
    {

    ?>
    Variable <?php echo $f;?>

    <?php
    }
    ?> 




    <?php

    while($data = mysql_fetch_assoc($r)){

    ?>



    <?php

    for ($d = 1; $d <= $nbre_champs; $d++)
    {

    echo "".htmlentities($data['reponse_contenu_jeux_'.$d.''],ENT_COMPAT,'utf-8')."";

    }

    ?>




    <?php

    }

    ?>




    <?php

    for ($f = 1; $f <= $nbre_champs; $f++)
    {

    ?>
    Variable <?php echo $f;?>

    <?php
    }
    ?>
     





    [/code]

    and this is editable_ajax.php :

    [code]
    require_once('../../includes/config.inc.php');

    $q_update = ' UPDATE `base`
    SET \''.$_GET['col'].'\'=\''.$_POST['value'].'\'
    WHERE `id`=\''.$_GET['id'].'\' ';

    $r = mysql_query($q_update) or exit('ERREUR - Fichier : ' .__FILE__. ' - Ligne : ' .__LINE__.' - Erreur : '.mysql_error().' - Requete : ' .$q_update);[/code]

    I hope that you can help me.

    A young developer

    :D)
  • allanallan Posts: 61,627Questions: 1Answers: 10,090 Site admin
    Hi,

    I rather suspect the main issue is here:

    [code]
    $('.center').editable( 'media/editable_ajax.php?id=<?php echo $data['id']; ?>&col=<?php echo $data['reponse_contenu_jeux_'.$d.'']?>', {
    [/code]

    Isn't that only going to output one row and column ID? As such you will always be updating the same cell in the database! You need to pass some extra parameters to jEditable's post, and I'm afraid I'm not sure how to do that, and don't have the time at the moment to look it up (sorry). I'd suggest posting on the jEditable forum (or whatever they use for support) on how you can post the ID for the row/column (you'll need to get that from somewhere as well - possibly an attribute in the HTML).

    I'll try to get some time to update my example to include posting these details.

    Regards,
    Allan
  • mickeymicmickeymic Posts: 23Questions: 0Answers: 0
    ok thanks

    if someone find a solution

    by
  • mickeymicmickeymic Posts: 23Questions: 0Answers: 0
    Hello,

    For your information, I ask to the support forum of Jeditable and this is the answer :

    [code]By default Jeditable submits the edited elements id as the id parameter. If you want to override this you can use "submitdata" parameter. In case you need to generate the id dynamically submitdata parameter can also be a function which returns a hash.

    $(".editable").editable("http://www.example.com/save.php", {
    submitdata : {foo: "bar"};
    });
    $(".editable").editable("http://www.example.com/save.php", {
    submitdata : function(value, settings) { return {foo: "bar"}; }
    });
    [/code]

    I don't really find a solution, but if it can help you...
This discussion has been closed.