Web Analytics Made Easy -
StatCounter Edit-in-place in a TABLE - CodingForum

Announcement

Collapse
No announcement yet.

Edit-in-place in a TABLE

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Edit-in-place in a TABLE

    PHP Code:
    require_once('includes/connection.php'
    PHP Code:
    require_once('includes/functions.php'
    PHP Code:
    include('includes/header.php'
    PHP Code:
    include('includes/sidebar.php'
    <div id="contentnorightbar">
    <h2 id="Intro"><a href="#">Registered Partners</a></h2>
    PHP Code:
    //Check if there is a page number
        
    if (!(isset($_GET['pagenum'])))
        {
            
    $pagenum 1;
        } else {
            
    $pagenum $_GET['pagenum'];
        }

        
    $data "SELECT * FROM partner";
        
    $result mysql_query($data$connection) or die(mysql_error());


        
    //check for number of rows
        
    $rows mysql_num_rows($result);
        
    //set no. of rows to display per page
        
    $page_rows 10;
        
    //find last page number
        
    $last ceil($rows/$page_rows);
        
    //this if statment will see that the page number is exact the max, not 1 below nor 1 above
        
    if ($pagenum 1)
        {
            
    $pagenum =1;
        } elseif (
    $pagenum $last)
        {
            
    $pagenum $last;
        }

        
    $max 'LIMIT ' .($pagenum 1) * $page_rows ',' .$page_rows;    

        
    // navigation
        
    $next $pagenum+1;
        
    $prev $pagenum-1;
        echo 
    " <div class=\"topnav\" align=\"right\"> ";
        echo 
    " <div class=\"numbers\"> $pagenum <small>of</small> $last &nbsp;&nbsp; | &nbsp;&nbsp; ";
        if(
    $pagenum == 1){
            echo 
    "Prev&nbsp;&nbsp;<a href='{$_SERVER['PHP_SELF']}?pagenum=$next'>Next ></a> ";
        }
        else if (
    $pagenum == $last) {
            echo 
    "<a href='{$_SERVER['PHP_SELF']}?pagenum=$prev'>< Prev</a>&nbsp;&nbsp Next";
        } else {
        echo 
    " <a href='{$_SERVER['PHP_SELF']}?pagenum=$prev'>< Prev</a>&nbsp;&nbsp; ";
        echo 
    " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next'>Next ></a> ";
        }
        
        echo 
    "</div></div>";

        if (
    $result) {
                
    //If the Query succeed
                
    print "<br /><table class='partners' border='1' cellpadding='0' cellspacing='0' width='100%'>
                        <tr>
                        <th>User</th>
                        <th>Name</th>
                        <th>Company</th>
                        <th>E-mail</th>
                        <th>Mobile</th>
                        <th>Edit</th>
                        </tr>"
    ;
                        
    $data_p mysql_query("SELECT * FROM partner $max") or die(mysql_error());
                        
                while(
    $info mysql_fetch_array($data_p)) {        
                    if(
    $i%== 0)
                    {
                    print 
    "<tr bgcolor='#FFF'>";
                    
    $i++;
                    }
                    else {
                    print 
    "<tr bgcolor='#EFF8FF'>";
                    
    $i++;
                    }
                    print 
    "<td>" $info['username'] . "</td>";
                    print 
    "<td>" ucfirst($info['firstname']) . " " ucfirst($info['lastname']) .  "</td>";
                    print 
    "<td>" $info['orgname'] . "</td>";
                    print 
    "<td>" $info['email'] . "</td>";
                    print 
    "<td>" $info['mobile'] . "</td>";
                    print 
    "<td><a href='../ipms/edit_partner.php?username={$info['username']}'>Edit</a></td></tr>";
                }
                print 
    "</table>";
                echo 
    " <br /> ";            
                
            } else {
                
    //Display error message
                
    echo "<p>Query failed. </p>";
                echo 
    mysql_error();
            } 
    Currently, I'm sending the user to another page(edit_partner.php) for editing a row. I want to do an in-place-edit in the table itself without sending the user to another page. Please guide me through this.

  • #2
    Use a GET method, then add the functions in the same file.

    PHP Code:
    if (isset($_GET["x"])) {
        
    $x explode(":",$_GET["x"]);

        switch(
    $do[0])
        {
            case 
    'main':
                
    main();
            break;
            
            case 
    'formula'//Formula chart
                
    formula();
            break;

     }

    So your link would look like this

    PHP Code:
    http://www.mysite.com/index.php?x=editrow:34 
    Rowsdower! has accused me of having mental problems, and the administrator allowed it. What a great forum huh?

    Comment


    • #3
      I have done what you said. $x is returning an Array. What to do with this Array ?

      see this pic: http://i42.tinypic.com/hwmn85.jpg

      Whenever a user clicks on the edit link, that particular row must change to input fields and the edit link must change to submit link. This is what I am trying to achieve.

      Comment


      • #4
        double- post
        Last edited by ashwinnaidu; Apr 6, 2009, 11:56 AM. Reason: double post

        Comment


        • #5
          I have managed to do this : http://i43.tinypic.com/eajvk9.jpg

          Code:
          <?php require_once('includes/connection.php') ?>
          <?php require_once('includes/functions.php') ?>
          <?php include('includes/header.php') ?>
          <?php include('includes/sidebar.php') ?>
          <div id="contentnorightbar">		
          <h2 id="Intro"><a href="#">Registered Partners</a></h2>
          	<?php	
          		include('includes/topnav.php');
          		if ($result) {
          			//If the Query succeed
          			print "<br /><table class='partners' border='1' cellpadding='0' cellspacing='0' width='100%'>
          					<tr>
          					<th>User</th>
          					<th>Name</th>
          					<th>Company</th>
          					<th>E-mail</th>
          					<th>Mobile</th>
          					<th>Edit</th>
          					</tr>";
          					$data_p = mysql_query("SELECT * FROM partner $max") or die(mysql_error());
          					
          			while($info = mysql_fetch_array($data_p)) {		
          				if($i%2 == 0)
          				{
          				print "<tr bgcolor='#FFF'>";
          				$i++;
          				}
          				else {
          				print "<tr bgcolor='#EFF8FF'>";
          				$i++;
          				}
          				if(isset($_GET['edituser'])) {
          					$edituser = $_GET['edituser'];
          					$pagenum = $_GET['pagenum'];
          				print "<form method=\"post\" action=\"partners_exp.php?edituser=\"{$info['$username']}>";
          				print "<td>" . $info['username'] . "</td>";
          				print "<td><input id=\"firstname\" type=\"text\" name=\"firstname\" value=" . $info['firstname'] . " ></td>";	
          				
          //				print "<td>" . ucfirst($info['firstname']) . " " . ucfirst($info['lastname']) .  "</td>";
          				print "<td>" . $info['orgname'] . "</td>";
          				print "<td>" . $info['email'] . "</td>";
          				print "<td>" . $info['mobile'] . "</td>";
          				print "<td><a href='partners_exp.php?pagenum={$pagenum}&edituser={$info['username']}'>Update</a></td></tr>";
          
          				} else {					
          					
          				print "<td>" . $info['username'] . "</td>";
          				print "<td>" . ucfirst($info['firstname']) . " " . ucfirst($info['lastname']) .  "</td>";
          				print "<td>" . $info['orgname'] . "</td>";
          				print "<td>" . $info['email'] . "</td>";
          				print "<td>" . $info['mobile'] . "</td>";
          //				print "<td><a href='partners_exp.php?edituser={$info['username']}'>Edit</a></td></tr>";
          				print "<td><a href='partners_exp.php?pagenum={$pagenum}&edituser={$info['username']}'>Edit</a></td></tr>";					
          				}
          			}
          			print "</table>";
          			echo " <br /> ";			
          			
          		} else {
          			//Display error message
          			echo "<p>Query failed. </p>";
          			echo mysql_error();
          		}
          ?>
          </div>	
          <?php include('includes/footer.php') ?>
          The problem is, whenever i click edit on one row, the code is being executed on all the rows. Can someone guide me from here .....

          Comment

          Working...
          X