0

i'm a newbie to web development world. Let me explain what i want.

id  car        make 
1   panamera   porsche  
2   italia     ferraris 
3   avantador  lamborghini  
4   slk        mercedes

I have this simple table in my database and i'm gonna echo this table in a while loop.

<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript" charset="utf-8"></script>
<script src="jquery.jeditable.js" type="text/javascript" charset="utf-8"></script>
</head>

<body>
<ul>
<?php  
$query = "SELECT * FROM inplace LIMIT 0, 6";    
$result = mysql_query($query) or die ('Query couldn\'t be executed');  
while ($row = mysql_fetch_assoc($result)) {
?>

<script type="text/javascript">
$(function() {
$("#<?php echo $row['id']; ?>").editable("http://www.example.com/save.php", { 
  indicator : "<img src='img/indicator.gif'>",
  tooltip   : "Doubleclick to edit...",
  event     : "click",
});
});
</script>

<?php
echo '<li id="'.$row['id'].'">'.$row['car'].'</li>';
echo '<li id="'.$row['id'].'">'.$row['make'].'</li>'; 
}
?>
</ul>
</body>

I'm trying to use Mika Tuupola's jEditable edit-in-place jQuery plugin. Here in this code, i have the jQuery code pasted inside the while loop. The first problem here is, only the "car" column is editable. I'm not able to edit the "make" column. And secondly, how do i post(update) the new values to database? Thanks.

  • In the future I would recommend that you refrain from making multiple questions about the same problem: http://stackoverflow.com/questions/9661614/how-to-post-values-to-server-jeditable/9662267#9662267 Or as an absolute last resort link to the other question you asked. I would follow Starx advice. In your other question I explained more than one way in detail how you can POST the data. Since you are now saying you would like the info to be posted to a DB, Do you want to replace the current values in the DB with the chosen values? – ityler22 Mar 12 '12 at 12:13
  • possible duplicate of [Using only one function to update different columns of a table in database](http://stackoverflow.com/questions/9460636/using-only-one-function-to-update-different-columns-of-a-table-in-database) – ahsteele Mar 15 '12 at 16:42

1 Answers1

0

You are using two elements with same id, which is both semantically and logically incorrect. Hence it is not working as you expected.

Either give same class or differenct ID's like shown in the following example.

echo '<li id="car'.$row['id'].'">'.$row['car'].'</li>';
echo '<li id="make'.$row['id'].'">'.$row['make'].'</li>';
Starx
  • 77,474
  • 47
  • 185
  • 261
  • Starx- Please take a look at the table at the beginning of the question. The "car" and "make" are the columns belonging to the same id. – generalsagar Mar 12 '12 at 11:18
  • @generalsagar, and thats what you are doing wrong. Didn't you read my answer? – Starx Mar 12 '12 at 11:20
  • Starx- I did read ur answer. Even if i use like id="car'.$row['id'].'" and id="make'.$row['id'].'" in the
  • , what id will i put in the script? Do u suggest me to use 2 scripts?
  • – generalsagar Mar 12 '12 at 16:35
  • @I said `same class` or `different id` the one in my example uses different Id. And If you use `id` you can minimize the redundacy, calling a common function, but rather than that, use class instead – Starx Mar 12 '12 at 16:42
  • Mate thanks. I tried using class and now i can edit both "car" and "make" columns. Now can u guide me how to update the new values to database? :) – generalsagar Mar 12 '12 at 16:54
  • @generalsagar, when the `
  • `get editable, you will get and `ok` which sends the request you selected script page. And thus the update will occur
  • – Starx Mar 12 '12 at 17:07
  • @generalsagar, visit the project page [here](https://github.com/tuupola/jquery_jeditable), there is already a php example with PDO. – Starx Mar 12 '12 at 17:17
  • Starx- i have that whole folder downloaded. But i couldnt understand the saving part. Thats why i'm asking here. – generalsagar Mar 13 '12 at 01:48