473,320 Members | 1,848 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Ajax in PHP

18
Hi all,
I am having a page where there is a drop down box for projects.Below that i had a list of users with check boxes. so wen i select a project in the drop down and assign some users to that project by checking on checkbox.
so here is my problem. wen i select the same project from drop down i should see the users who are assigned to that project as checked. so wen i select another project then users assigned to that project should be checked.

on change of the project i need to get the users who are assigned to that project as checked and others as unchecked.

I came to know that this can be done by Ajax. so can any one help me please....


Below is the code i habe written.
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. ob_start();
  3. @session_start();
  4. require_once ("check.php");
  5. createsessions($username,$password,$userid,$projectid,$projectname,$filename,$size,$allocatedmemory,$answer,$usedmemory,$Remainingmemory,$result,$data3);
  6.     include 'connection.php';
  7.     $sql="SELECT projectname from projects where createdby='".mysql_real_escape_string($_SESSION['username'])."'";
  8.     mysql_error();
  9.     $result=mysql_query($sql);
  10.     $options=""; 
  11.     while ($row=mysql_fetch_array($result)) 
  12.     {
  13.         $id=$row["projectid"];
  14.         $projectname=$row["projectname"];
  15.         $options.="<option value=\"$projectname\">".$projectname.'</option>';
  16.     }
  17.     $num=mysql_num_rows($result);
  18.     $sql2="SELECT * FROM users where reportingto='".mysql_real_escape_string($_SESSION['username'])."' and role='2'";
  19.     mysql_error();
  20.     $result2=mysql_query($sql2);
  21.     $num=mysql_num_rows($result2); 
  22.     $sql3="select userid from projectassign where projectassign='$projectassign'";
  23.      mysql_error();
  24.     $result3=mysql_query($sql3);
  25.     $num1=mysql_num_rows($result3);
  26.     $i=0;
  27.     while ($i < $num1)
  28.     {
  29.         $userid=mysql_result($result3,$i,"userid");
  30.         echo $userid;  // the userid's who are assigned to the project selected in drop down wil be printed here. Now i need those userid's check box should be checked.
  31.         $i++; 
  32.     }
  33.  
  34.     ?>
  35.  
  36. <head>
  37.  
  38. <link rel="stylesheet" type="text/css" href="style.css"/> 
  39. <script language="javascript" type="text/javascript" src="back.js" ></script>
  40.  <body onLoad="backButtonOverride()">
  41. <script language="javascript" type="text/javascript">
  42.         function check()
  43.         {
  44.  
  45.             if(document.getElementById('prolist').selectedIndex == 0)
  46.             {
  47.                 alert('Please select a Project');
  48.                 return false;
  49.  
  50.             }
  51.            /* var txt=document.getElementsByName("checkbox[]");
  52.           var chk=false;
  53.            for(i=0;i<txt.length;i++)
  54.            {
  55.              if(txt[i].checked==true)
  56.              {
  57.                  chk=true;
  58.              }
  59.            }
  60.            if(chk==false)
  61.            {
  62.            alert("please select the checkbox.");
  63.            return false;
  64.            } */                   
  65.  
  66.         }
  67.         </script>                                 
  68. <form action="projectassign.php" method="post">
  69. <table width="100%">
  70. <tr><td> <img src="Logofinalcopy.gif">
  71. </td></tr></table><br><hr style="color: red;">
  72. <table align="right"> 
  73.     <tr>
  74.         <td align="right" style="width: 50px">   
  75.             <td align="right" style="color: navy;"><strong><?php echo "Welcome ".$_SESSION[username];?>,</strong></td><td><a href="logout.php">Logout</a></td>
  76.         </td>
  77.         </tr></table>
  78.         <table><tr>
  79.         <td><a href="Admin.php">Home</a></td>
  80.         <td>&nbsp&nbsp&nbsp&nbsp 
  81.         <a href="Projectmgmt.php">Projects</a></td>
  82.         <td>&nbsp&nbsp&nbsp&nbsp<a href="projectassign.php">Project Assign</a></td>
  83.         </tr>
  84.         </table>  
  85.  
  86.     <table align="center"><td style="color: navy;"><h2>Project assign</h2></td>
  87.     </tr></table>
  88.     <table align="center">
  89.     <tr>
  90.         <td style="color: navy;">Projectassign</td>
  91.         <td><select id="prolist" name="projectassign">
  92.         <option  value="<?php echo '$projectassign';?>" >----select project----</option><?php echo $options ?> 
  93.         </select>
  94.         </td>
  95.     </tr>
  96.     </table>  
  97.     <br><br><br>  
  98.     <table border="1" cellspacing="0" cellpadding="0" align="center" style="width: 500px" bordercolor="red">
  99.     <tr>
  100.         <th></th>
  101.         <th style="color: navy;">Userid</th>
  102.         <th style="color: navy;">Username</th>
  103.  
  104.     </tr>
  105.     <?php
  106.     $sno=1;
  107.     while($row=mysql_fetch_array($result2, MYSQL_ASSOC)){
  108.     ?>
  109.      <tr>
  110. <td><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $row['userid']; ?>"></td>
  111. <td><? echo $row['userid']; ?></td>
  112. <td><? echo $row['username'];?></td>
  113. </tr>
  114. <?php
  115.     $sno=$sno+1;
  116. }
  117. ?>
  118.     </table>
  119.  
  120.     <?php
  121.  
  122. if(isset($_POST['Submit']))
  123.  
  124.     {  
  125.         $checkbox=$_POST['checkbox'];  
  126.         for($i=0;$i<count($checkbox);$i++)
  127.         {
  128.         $del_id = mysql_real_escape_string($checkbox[$i]); 
  129.         $query="select projectassign from projectassign where projectassign='$_POST[projectassign]' and userid='$del_id' ";
  130.         mysql_error();  
  131.         $result=mysql_query($query);
  132.         $ans=mysql_num_rows($result);        
  133.         if($ans==0)
  134.         {        
  135.             $sql3 = "INSERT INTO projectassign(projectassign,userid)values('".mysql_real_escape_string($_POST['projectassign'])."','$del_id')";
  136.             mysql_error();
  137.             $result = mysql_query($sql3);
  138.             echo "<script language='javascript'>
  139.             alert('Project assigned');
  140.             </script>";
  141.         }
  142.         else{
  143.             echo "<script language='javascript'>
  144.             alert('Project already assigned');
  145.             </script>";
  146.         }
  147.  
  148.        }
  149.  
  150.     }
  151.  
  152.     ?> 
  153.     <br><table align="center"><tr><td><input type="submit" name="Submit"  value="Submit" onclick="return check();"></td></tr></table> 
  154.     </form>
  155.     </body>
  156.     </head>
Jun 7 '10 #1
2 1305
Atli
5,058 Expert 4TB
Hey.

To do that you would have to use JavaScript. Use the onchange event of your <select> box to execute a JavaScript function. Have the function send the selected option to a PHP script, using AJAX, which should return a list of names assigned to that option. Then use JavaScript to manipulate the DOM to check/uncheck the appropriate boxes according to that list.

If you are new to AJAX, start by going through a basic tutorial. AJAX is simple enough to learn in a matter of hours (if not minutes), but it requires you to know JavaScript as well. -- AJAX is just an object, used in JavaScript code.
Jun 7 '10 #2
johny10151981
1,059 1GB
I Completely agree with Atli.

Please follow the link(i got it on google searching). Simplest and very much useful example
simple ajax example

only instead of cgi use your php script. Another issue Ajax is completely client side scripting nothing to do with php. Whatever request a server get it will process. It can be from Ajax or even if you design a desktop application with c/java, PHP will reply same.

best regards,
johny
Jun 8 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Yarco | last post by:
I want to use "Ajax" to create my web for hobby. But i don't know whether "Ajax" is mature... And what about with php? Someone have experience on it? ....
4
by: bobzimuta | last post by:
I'm creating a simple AJAX library. It's an object that will return an array containing the response text or xml. I'm trying to find a way to assign the response as a property of the object, but...
0
by: melledge | last post by:
Ajax Developers' Day added to XTech 2006 agenda XTech 2006 - 17-19 May - Hotel Grand Krasnopolsky - Amsterdam, The Netherlands
10
by: Steve | last post by:
I need to build a very dynamic client and would be interested in knowing the pros and cons of using JSF and Ajax to accomplish this. Thanks. Steve
0
by: melledge | last post by:
Ajax Developers' Day to Kick Off XTech 2006 Conference Industry experts offer insight into next generation of the Web ALEXANDRIA, VIRGINIA, USA - April 25, 2006 - In response to the rapidly...
1
by: www.web20developers.com | last post by:
http://www.web20developers.com http://www.web20developers.com/index.php?option=com_content&task=view... Ajallerix : AJAX, simple, fast Web image gallery demo ; at Novell AJAX -...
10
by: =?Utf-8?B?WWFua2VlIEltcGVyaWFsaXN0IERvZw==?= | last post by:
controlsPlease could some of you here post some of your live examples of AJAX (esp drag panels, collapsable panels, and popup menu.) (It's one thing to talk about how great something is, but it's...
2
by: soni2926 | last post by:
hi, does anyone know of any good books on ajax and asp.net, one that teaches ajax itself before jumping in atlas? I wanted to get an understanding of ajax and how to use it, most books i've seen...
1
by: shaunwo | last post by:
I'm an AJAX / DOM Novice (at best) and trying to figure out how to write the value to a couple input fields. I don't remember exactly where I got the ajax.js file I'm using from (went to the website...
11
by: =?Utf-8?B?R2VyaGFyZA==?= | last post by:
I have run into a situation that if a page/tab that uses the Ajax toolkit (using .net version 3.5) is closed before the Ajax enable controls complete loading, then IE locks up. Does it in both IE7...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.