SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast tommy168's Avatar
    Join Date
    Feb 2011
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Sortable problem

    Hey guys

    I posted a similar thread before, but now the question is different, it's related to sortable

    This is the code for the table:

    PHP Code:
    $result $conn->query("SELECT query, link, pro,pro_update,ana,ana_update,cell,cell_update,cellother,cellother_update,gen,gen_update,genother,genother_update,author,author_update,other,other_update,date,id
    FROM mailing_list
    WHERE email = '
    $email'
    ORDER BY 
    $order LIMIT $start_row$max_per_page;");

    echo 
    "<table class=\"sortable\" id=\"query_quick2\" width=\"100%\" >\r\n";
    echo 
    "\t<tr><th class=\"sorttable_alpha\" >Updated Query</th><th width=\"10\" class=\"sorttable_alpha\" >Link</th>
    <th class=\"sorttable_alpha\" >Promoter Locus</th><th class=\"sorttable_alpha\" >Update</th>
    <th class=\"sorttable_alpha\" >Anatomical Area</th><th class=\"sorttable_alpha\" >Update</th>
    <th class=\"sorttable_alpha\" >Cell Type</th><th class=\"sorttable_alpha\" >Update</th>
    <th class=\"sorttable_alpha\" >Other Cell Type</th><th class=\"sorttable_alpha\" >Update</th>
    <th class=\"sorttable_alpha\" >Genetic Background</th><th class=\"sorttable_alpha\" >Update</th>
    <th class=\"sorttable_alpha\" >Other Gen. Back.</th><th class=\"sorttable_alpha\" >Update</th>
    <th class=\"sorttable_alpha\" >Author</th><th class=\"sorttable_alpha\" >Update</th>
    <th class=\"sorttable_alpha\" >Other</th><th class=\"sorttable_alpha\" >Update</th>
    <th class=\"sorttable_mmdd\" >Date</th><th class=\"sorttable_nosort\" ></th><th class=\"sorttable_nosort\" ></th>\r\n"
    ;

    if(
    $result->num_rows){
    while (
    $row $result->fetch_array()){
    $RowCount ++;
    $row_color = ($RowCount 2) ? $color1 $color2;
    echo 
    "<form method = \"post\" action=\"{$_SERVER['PHP_SELF']}\">";
    echo 
    "\t<tr id=\"{$row['id']}\" class=\"$row_color\" >
    <td>
    {$row['query']}</td><td>{$row['link']}</td>
    <td>
    {$row['pro']}</td><td>{$row['pro_update']}</td><td>{$row['ana']}</td>
    <td>
    {$row['ana_update']}</td><td>{$row['cell']}</td><td>{$row['cell_update']}</td><td>{$row['cellother']}</td>
    <td>
    {$row['cellother_update']}</td><td>{$row['gen']}</td><td>{$row['gen_update']}</td><td>{$row['genother']}</td>
    <td>
    {$row['genother_update']}</td><td>{$row['author']}</td><td>{$row['author_update']}</td><td>{$row['other']}</td><td>{$row['other_update']}</td>
    <td>
    {$row['date']}</td>
    <td><input type=\"submit\" name=\"edit_mail\" value = \"Edit\"/></td>
    <td><input type =\"hidden\" name = \"id\" value=\"
    {$row['id']}\"/></td>
    <td><input type=\"submit\" name=\"delete_mail\" value =\"Delete\"/></td>
    </tr>"
    ;
    echo 
    "</form>";


    }
    }

    echo 
    "</table>"
    This is an excerpt of the script which deletes the specific entry:

    PHP Code:
    } elseif(isset($_SESSION['user_id']) AND isset($_POST['delete_mail'])){
    //user is deleting existing queries
    $connect=db_connect_2();
    $id mysqli_real_escape_string($connect$_POST['id']);


    $sql2 "DELETE FROM mailing_list WHERE id='$id'";
    $result mysqli_query($connect$sql2) or mysqli_error($conn);

    $msgs[] = "Queries DELETED successfully.";
    $body "account.php";


    I can delete the specific entry like usual at the beginning

    but right AFTER i sort the table by clicking a column heading, say, promoter locus, (using sortable.js)

    and then when i try to delete a specific entry, problem arises.

    Instead of deleting the entry i want, it always deletes the LAST entry.

    Now as you can see, i select a specific value for $id, using post method from a form

    But shouldn't the value of $id point to the entry i want to delete when i click the "delete" button near it? (i mean it works fine before i sort the table)

    Any help would be greatly appreciated

    Thanks.

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,508
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    You're sorting with js? Does it sort the hidden fields as well?
    Do a print_r of the $_POST array to see the data your form is sending.

  3. #3
    Non-Member
    Join Date
    Aug 2010
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In computer science, a sorting algorithm is an algorithm that puts elements of a list in a certain order. The most-used orders are numerical order and lexicographical order.

  4. #4
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,508
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by niftydirectt View Post
    In computer science, a sorting algorithm is an algorithm that puts elements of a list in a certain order. The most-used orders are numerical order and lexicographical order.
    And how does this address the OP's problem?

  5. #5
    SitePoint Enthusiast tommy168's Avatar
    Join Date
    Feb 2011
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Problem solved,

    it turned out that I just needed to put <form>...</form> inside <tr>...</tr>

    so no it's not a problem with sortable.js

    now i can delete whichever entry i want no matter how i sort the table

    Thanks.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •