Jump to content

In-place-edit in a table


ashwinnaidu

Recommended Posts

 

File: Partners.php

 

<?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++;

}

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();

}

?>

</div>

<?php include('includes/footer.php') ?>

 

 

File: topnav.php

 

<?php

 

//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    |    ";

if($pagenum == 1){

echo "Prev  <a href='{$_SERVER['PHP_SELF']}?pagenum=$next'>Next ></a> ";

}

else if ($pagenum == $last) {

echo "<a href='{$_SERVER['PHP_SELF']}?pagenum=$prev'>< Prev</a> &nbsp Next";

} else {

echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$prev'>< Prev</a>   ";

echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next'>Next ></a> ";

}

 

echo "</div></div>";

 

?>

 

This code populates info from database(10 rows per page). Each row has has an Edit Link which takes the user to another page for editing.

Now, I want to do an in-place-edit, right in the table. Can anyone guide me through !

 

regards,

Ashwin.

 

Link to comment
Share on other sites

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

But instead of one row, all the rows are being selected. What am I doing wrong here !

 

@corbin: I'm familiar with Javascript, Is there any tutorial that I can read to achieve what I am trying to do.

 

Updated 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') ?>

 

 

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.