Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8356603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:14:19+00:00 2026-06-09T10:14:19+00:00

I have a web site which enables user to add or delete their own

  • 0

I have a web site which enables user to add or delete their own favorite books. I added “add” and “delete” button every row in page. I can add favorite books in session array and there is no problem about it. But I can not delete a row from “user’s favorite book list.”

I used jquery, ajax. I could unset row but what I want is delete that row from session completely and order again. Despite the fact that I unset the row, element number of session does not change.

Here is code :

    //There are rows in $newdata. That is to say, newdata array is not empty now.
    // I just add newdata array here to show that there is an array called newdata.

    var $newdata = array();

    function delete_row($rowid) {

    if (isset($rowid)) {

    $this->newdata = $this->session->userdata('contents');
    unset($this->newdata[$rowid]['id']);
    unset($this->newdata[$rowid]['name']);
    unset($this->newdata[$rowid]['author']);
    unset($this->newdata[$rowid]['year']);

    $this->session->set_userdata(array('contents' => $this->newdata));

    $contents = $this->session->userdata('contents');

    $i = 0;

        foreach ($contents as $key)         
        {
            if ($key['id'] != "") {
                $i++;

            $this->newdata[$i]['id'] = $key['id'];
            $this->newdata[$i]['name'] = $key['name'];
            $this->newdata[$i]['author'] =$key['author'];
            $this->newdata[$i]['year'] =$key['year'];

            } else {

            }
        }

    $this->session->set_userdata(array('contents' => $this->newdata));

    } else {

        echo "There is no row to be deleted";
    }
}

Here is view code(html) :

<div>

        <?php 

        if (count($contents)==0) {
        echo 'There is no favorite book';
        } else {

        echo '<table class="table table-striped">';

        $i = 0;
        echo count($contents);
        foreach ($contents as $items) {

        echo '<tr>';
        echo '<td>'.$items['id'].'</td>';
        echo '<td>'.$items['name'].'</td>';
        echo '<td>'.$items['author'].'</td>';
        echo '<td>'.$items['year'].'</td>';
        echo '<td><button id='.$i .' class="delete_row"><b>DELETE</b></button></td>';
        echo '</tr>';
        $i++;

    }
    echo '</table>';

    }
        ?>
    </div>

Here is jquery code :

$('.delete_row').click(function(event) {
event.preventDefault();
var id = $(this).attr("id"); 
window.location.href = '/favorite/delete_row/'+id;

 });
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T10:14:20+00:00Added an answer on June 9, 2026 at 10:14 am

    I think the problem lies in the del button id. You’re using the $i variable instead of $items['id']. So the JS redirect will send the count int and not the item id to the delete page.

    Change:

    echo '<td><button id='. $i .' class="delete_row"><b>DELETE</b></button></td>';
    

    Into:

    echo '<td><button id='. $items['id'] .' class="delete_row"><b>DELETE</b></button></td>';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a delete button on my web site which I want to add
I used to have an embedded user control in an ASP.NET web site which
Here's the setup. I have web site which is essentially a simple CMS. Here
I have created a web site which is valid to strict XHTML and passes
I have a PHP5/Zend Framework 1.8.1 web site which is located at: http://www.example.com/foo The
I'm a beginner with Zend. I have a little web site in which I
I have a web site with an API which publishes the information using JSON.
i have to reach a web site content which have an url like that
I have a Clustered Windows Hosting site which currently hosts an MVC Web Application
I have an ASP.NET MVC web site. I have many actions which require authentication

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.