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?a id=";
var url_remove = "testajax.php?a ct=rem&aid=";
function handleHttpRespo nse() {
if (http.readyStat e == 4) {
if(http.status= =200) {
var results=http.re sponseText;
document.getEle mentById('divre sult').innerHTM L = results;
}
}
}
function request_table_a jax2_add(aid) {
http.open("GET" , url+aid, true);
http.onreadysta techange = handleHttpRespo nse;
http.send(null) ;
}
function request_table_a jax2_remove(aid ) {
http.open("GET" , url_remove+aid, true);
http.onreadysta techange = handleHttpRespo nse;
http.send(null) ;
}
function getHTTPObject() {
var xmlhttp;
if(window.XMLHt tpRequest){
xmlhttp = new XMLHttpRequest( );
}
else if (window.ActiveX Object){
xmlhttp=new ActiveXObject(" Microsoft.XMLHT TP");
if (!xmlhttp){
xmlhttp=new ActiveXObject(" Msxml2.XMLHTTP" );
}
}
return xmlhttp;
}
function request_table_a jax2_1() {
http.open("GET" , url, true);
http.onreadysta techange = handleHttpRespo nse;
http.send(null) ;
}
var http = getHTTPObject() ;
</script>
</head>
<body>
<div id="divresult"> </div>
<script type="text/javascript">
request_table_a jax2_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=mysq l_query("DELETE FROM ajax2 WHERE id_ajax1=$_GET[aid]");
} else {
$get_query=mysq l_query("SELECT * FROM ajax1 WHERE id=\"$_GET[aid]\"") or die(mysql_error ());
if(mysql_num_ro ws($get_query) > 0) {
$add_query=mysq l_query("INSERT ajax2(id_ajax1) VALUES(\"$_GET[aid]\")");
}
}
}
?>
<table border="0" width="70%"><tr ><td width="35%" valign="top">
<?php
$query=mysql_qu ery("SELECT * FROM ajax1") or die(mysql_error ());
$row = mysql_num_rows( $query);
for($i = 0; $i < $row; $i++){
$name = mysql_result($q uery,$i,'name') ;
$id = mysql_result($q uery,$i,'id');
$query_ajax2=my sql_query("SELE CT * FROM ajax2 WHERE id_ajax1=$id");
if(mysql_num_ro ws($query_ajax2 ) > 0 ) {
echo "<img name='aid' id='aid' src=\"images/icon2.gif\" onClick=\"reque st_table_ajax2_ remove($id);\"> <font face='verdana' size='2'><b>$na me</font><br>";
} else {
echo "<img name='aid' id='aid' src=\"images/icon1.gif\" onClick=\"reque st_table_ajax2_ add($id);\">&nb sp;<font face='verdana' size='2'><b>$na me</font><br>";
}
}
?>
</td><td width="35%" valign="top">
<?php
$query1=mysql_q uery("SELECT * FROM ajax2") or die(mysql_error ());
if(mysql_num_ro ws($query1)>0){
for($i=0;$i<mys ql_num_rows($qu ery1);$i++){
$id=mysql_resul t($query1, $i, 'id_ajax1');
$query2=mysql_q uery("SELECT name FROM ajax1 WHERE id=$id") or die(mysql_error ());
if(mysql_num_ro ws($query2)>0){
for($j=0;$j<mys ql_num_rows($qu ery2);$j++){
$name1 = mysql_result($q uery2,$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..