Jump to content

to move up and down records in html table


chit15

Recommended Posts

I have written code to move records up and down but it does not work and I have tried it on simple table it works fine can anyone help what is problem in my code?
 
if ((empty($_POST))&&(empty($_GET))) 
  list_users(); 
  die(); 
}

 

function list_users() 
{    
    echo "<form method='post'>
  <table width='50' align='right' border='0' cellspacing='0' cellpadding='0'> 
 <tr>
 <td colspan='2' align='center'>"; ?>
 <?php if(isset($_SESSION['username']))
{
$s="Hello,".$_SESSION["username"];
$r=$_SESSION["userrole"];
echo $s;
}    
 echo "<a href='logout.php' id='logout'>Logout</a></td>          
 </tr> 
 </table>
        <table width='600' align='center' cellpadding='0' cellspacing='0' border='1' id='tableID'> 
        <tr><td colspan='7' align='center' style='font-size:18px; font-weight:bold;'>Displayed Data</td></tr> 
        <tr><td colspan='7'><a href='".$_SERVER['PHP_SELF']."?action=add'>Add a new contact</a></td></tr>";
       
   $y = 0;  
$sortDefault = 'id'; 
 
// select array
$sortColumns = array('id','first_name','last_name');
 
// select query with sort 
$sort = isset($_GET['sort']) && in_array($_GET['sort'], $sortColumns) ? $_GET['sort'] : $sortDefault; 
$order = (isset($_GET['order']) && strcasecmp($_GET['order'], 'DESC') == 0) ? 'DESC' : 'ASC'; 
   
    $sql = "select * from contacts ORDER BY $sort $order"; 
    $result = mysql_query($sql) or die ("Can't run query because ". mysql_error()); 
 
     if (mysql_num_rows($result)){ 
(($y % 2) == 0) ? $bgcolor = "#8FBC8F" : $bgcolor=" #9ACD32";        
       echo " 
  <tr style='background-color:#5CB3FF' align=center>";?>
 <!-- <td><input type='checkbox' id='all' name='mainchk' /></td>-->
      <td>Chk</td>
  <td><a href='?sort=first_name&order=<?php echo $order =='DESC' ? 'ASC' : 'DESC' ?>'>Name</a></td>
  <td><a href='?sort=last_name&order=<?php echo $order =='DESC' ? 'ASC' : 'DESC' ?>'>LastName</td>
       <td><a href='?sort=email&order=<?php echo $order =='DESC' ? 'ASC' : 'DESC' ?>'>Email</td>
  <td>Status</td>
       <td>Move</td>
  <td id="actid">Action</td>
<?php "</tr>";
      while($rows = mysql_fetch_assoc($result)){       
 
        $name   = $rows['first_name'];
$lname  = $rows['last_name']; 
$email  = $rows['email']; 
        $status = $rows['contact_status']; 
        $id     = $rows['id']; 
               
        ($status == 0) ? $status = "Available to contact" : $status = "Do not contact at present."; 
      
   echo"<tr align=center style='background-color:#C0C0C0'>   
<td><input type='checkbox' value='$id' name='data[]' id='data'></td>
<td>$name</td>
<td>$lname</td>
<td>$email</td>
<td>$status</td>
<td><a href='#' class='up'>Up</a><a href='#' class='down'>Down</a></td>
<td><a href='".$_SERVER['PHP_SELF']."?action=delete&id=$id' class='confirmation'><img src='delete.png' height='16px' width='16px'></a>  
<a href='".$_SERVER['PHP_SELF']."?action=edit&id=$id'><img src='write.png' height='16px' width='16px'></a></td>
<tr>"; 
        $y++;  
      }
      echo"</table>"; 
  }
  else
  {    
    echo "<tr><td colspan='2' align='center'><b>No data found.</b></td></tr>"; 
  }
  echo"<div align='center' width='50' ><a href='#' id='all' name='mainchk'>CheckAll/UnCheckAll</a>  
  <input type='image' src='delete.png' alt='Submit' width='16px' height='16px' id='delete'>  
  <input type='image' src='write.png' alt='Submit' width='16px' height='16px' id='editbulk'>
  </div></form>";

 

 

//Jquery for moving records up & down

 

$(".up,.down").click(function(){
        var row = $(this).parents("tr:first");
        if ($(this).is(".up")) {
            row.insertBefore(row.prev());
        } else {
            row.insertAfter(row.next());
        }
    });
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.