Its me sujith
i've done something with AJAX.
but for the rest i need someo ones help..
i've done half the work.
there are two tables. "ajax1" and "ajax2" (check db.sql)
db.sql
Expand|Select|Wrap|Line Numbers
- CREATE TABLE `ajax2` (
- `id` int(11) NOT NULL auto_increment,
- `id_ajax1` int(11) NOT NULL,
- PRIMARY KEY (`id`)
- );
- INSERT INTO `ajax2` VALUES (145, 4);
- CREATE TABLE `ajax1` (
- `id` int(11) NOT NULL auto_increment,
- `name` varchar(20) NOT NULL,
- PRIMARY KEY (`id`)
- );
- INSERT INTO `ajax1` VALUES (1, 'Habeeb');
- INSERT INTO `ajax1` VALUES (2, 'Sujith');
- INSERT INTO `ajax1` VALUES (3, 'Jeevan');
- INSERT INTO `ajax1` VALUES (4, 'Aditi');
- INSERT INTO `ajax1` VALUES (5, 'Ramu');
- INSERT INTO `ajax1` VALUES (6, 'Raghavan');
[HTML]<html>
<head>
<script type="text/javascript">
var url = "testajax.php?aid=";
var url_remove = "testajax.php?act=rem&aid=";
function handleHttpResponse() {
if (http.readyState == 4) {
if(http.status==200) {
var results=http.responseText;
document.getElementById('divresult').innerHTML = results;
}
}
}
function request_table_ajax2_add(aid) {
http.open("GET", url+aid, true);
http.onreadystatechange = handleHttpResponse;
http.send(null);
}
function request_table_ajax2_remove(aid) {
http.open("GET", url_remove+aid, true);
http.onreadystatechange = handleHttpResponse;
http.send(null);
}
function getHTTPObject() {
var xmlhttp;
if(window.XMLHttpRequest){
xmlhttp = new XMLHttpRequest();
}
else if (window.ActiveXObject){
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
if (!xmlhttp){
xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
}
}
return xmlhttp;
}
function request_table_ajax2_1() {
http.open("GET", url, true);
http.onreadystatechange = handleHttpResponse;
http.send(null);
}
var http = getHTTPObject();
</script>
</head>
<body>
<div id="divresult"></div>
<script type="text/javascript">
request_table_ajax2_1();
</script>
</body>
</html>
[/HTML]
testajax.php
[PHP]<?php
mysql_connect("localhost", "username", "");
//mysql_connect("localhost", "username", "");
mysql_select_db("test") or die(mysql_error());
//mysql_select_db("db_ajax_habi") or die(mysql_error());
if(strlen(trim($_GET['aid']))>0) {
if($_GET['act']=='rem') {
$rem_query=mysql_query("DELETE FROM ajax2 WHERE id_ajax1=$_GET[aid]");
} else {
$get_query=mysql_query("SELECT * FROM ajax1 WHERE id=\"$_GET[aid]\"") or die(mysql_error());
if(mysql_num_rows($get_query) > 0) {
$add_query=mysql_query("INSERT ajax2(id_ajax1) VALUES(\"$_GET[aid]\")");
}
}
}
?>
<table border="0" width="70%"><tr><td width="35%" valign="top">
<?php
$query=mysql_query("SELECT * FROM ajax1") or die(mysql_error());
$row = mysql_num_rows($query);
for($i = 0; $i < $row; $i++){
$name = mysql_result($query,$i,'name');
$id = mysql_result($query,$i,'id');
$query_ajax2=mysql_query("SELECT * FROM ajax2 WHERE id_ajax1=$id");
if(mysql_num_rows($query_ajax2) > 0 ) {
echo "<img name='aid' id='aid' src=\"images/icon2.gif\" onClick=\"request_table_ajax2_remove($id);\">  ;<font face='verdana' size='2'><b>$name</font><br>";
} else {
echo "<img name='aid' id='aid' src=\"images/icon1.gif\" onClick=\"request_table_ajax2_add($id);\"> <f ont face='verdana' size='2'><b>$name</font><br>";
}
}
?>
</td><td width="35%" valign="top">
<?php
$query1=mysql_query("SELECT * FROM ajax2") or die(mysql_error());
if(mysql_num_rows($query1)>0){
for($i=0;$i<mysql_num_rows($query1);$i++){
$id=mysql_result($query1, $i, 'id_ajax1');
$query2=mysql_query("SELECT name FROM ajax1 WHERE id=$id") or die(mysql_error());
if(mysql_num_rows($query2)>0){
for($j=0;$j<mysql_num_rows($query2);$j++){
$name1 = mysql_result($query2,$j,'name');
echo "<font face='verdana' size='2' color='red'><b>$name1</b></font><br />";
}
}
}
}
?>
</td></tr></table>
[/PHP]
Now i can do the clicking process.
im able to add data to table "ajax2" from table "ajax1" by clickin on the "add" button.
deletion also possible.
But now my problem is drag and drop.
i need to drag data in the second column (ie; the result of clicked items) upwards and downwards..
but im not able to do it..
can u plz halp me to do that??
run it on Mozilla firefox..
then u will understand my problem..
plz help me..