Jump to content

Ajax update via while loop


generalsagar

Recommended Posts

i'm learning php, ajax, jquery..the web development stuff. I just learnt how to do inplace edit and update the values to database via ajax. This is how my trainer taught me. Page 1 -

 

<html>

<head>

<script type="text/javascript" src="scriptaculous/lib/prototype.js"></script>

<script type="text/javascript" src="scriptaculous/src/scriptaculous.js"></script>

<script type="text/javascript">

 

function load_auto(){

new Ajax.InPlaceEditor(

'hello',

'update1.php'

);

 

new Ajax.InPlaceEditor(

'hello2',

'update2.php'

);

}

</script>

</head>

<body onLoad="javascript:load_auto();">

<div id="hello" name="hello">hello world</div>

<div id="hello2" name="hello2">hello world second one</div>

</body>

</html>

 

So, in page 1, i have created a couple of divs with some text. Both the divs have their own ids. In javascript, i'm writing a function called "load_auto" and writing a built-in function called new Ajax.InPlaceEditor() and passing two parameters('hello', 'update1.php') in it. One is the id of the div, and the second is the name of the page where i'm sending the value. My trainer says that for each div, we need to write a separate function(new Ajax.InplaceEditor) like this and everytime we need to send the values to separate pages. Take a look at the second div. I'm sending the value to one more page called 'update2.php'. And below is the update1.php page where i'm sending the value of the first div-

 

<?php

$con = mysql_connect("localhost","root","");

if(!$con)

{

die("Cannot Connect to Database");

}

$select_db = mysql_select_db("inplace");

 

if(!$select_db)

{

die("Cannot Select the Database");

}

 

$id = $_REQUEST["value"];

$hello = $_POST["value"];

$sql = "update inpl set `hello` = '$id' WHERE `uid`=1";

$res = mysql_query($sql);

$count = mysql_affected_rows();

if($count>0)

{

echo $id;

}

?>

 

Here, i'm making a basic database connection and writing a query to update it in the database. So this will update only the first div's value. My first question here is,

1- What does this- $id = $_REQUEST["value"]; actually do? and what is that "value"?

2- Is this the correct method? What if i had 50 divs and i want to update all of them via ajax?

3- How to update the values via while loop? Say for example, i have echoed a table which reads out all the 50 users and their details in a while loop. name, email, phone, address..etc. If i wanna use inplace edit thing and update it via ajax, how to do it?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.