Welcome Guest, Not a member yet? Register   Sign In
To have each table have it's own edit/delete button
#1

[eluser]theif_of_always[/eluser]
My edit/delete button only targets the last entry into the table. So, for example, if I had

Book Info 3
[edit/delete button]

Book Info 2
[edit/delete button]

Book Info 1
[edit/delete button]

Regardless to which edit button I press, it only takes me to the latest in the table. How do I get it so, it will only target a particular book info entry? So, if I click the edit/delete button under book info 2, it will take me to book info 2 and not book info 3 which it always does, even if I clicked edit on book info 1 as well.

Here is the initially "book view" page.
Code:
<?php
$this->load->view("header_view");
?>


<?php
  $atts = array(
    'width' => '800',
    'height' => '600'
   );


     foreach($bookInformation->result() as $bookInformation) {
    
     echo "<br />";
     echo "<br />";
  echo "<strong>Book ID</strong>: " . $bookInformation->bookID . "<br />";
  echo "<strong>Book Author</strong>: " . $bookInformation->author . "<br />";
  echo "<strong>Book Title</strong>: " . $bookInformation->bookTitle . "<br />";
  echo "<strong>Book ISBN</strong>: " . $bookInformation->isbn . "<br />";
  echo "<strong>Book Description</strong>: " . $bookInformation->description . "<br />";
        echo "<strong>Book Category</strong>: " . $bookInformation->categoryID . "<br />";

        echo anchor_popup('dashboard/get_edit_books_form', 'Edit/Delete', $atts);

        echo "<br />";
     echo "<br />";
        echo anchor_popup('dashboard/get_category_add_form', 'Add Category', $atts);


}



?&gt;

Here is the "get_edit_books_form" page

Code:
&lt;?php
  
echo $this->session->flashdata('message');
echo validation_errors();
$id = array('id' => 'BookForm');
echo form_open('dashboard/update_books', $id);
$bookInformation = $bookInformation->row();  
  
?&gt;

&lt;?php echo "EDIT/UPDATE" ?&gt;
<br />
<br />

    &lt;input name="bookID" type="hidden" value="&lt;?php echo $bookInformation-&gt;bookID; ?&gt;" /&gt;
  
<label for="bookTitle">Book Title</label><br />
&lt;input name="bookTitle" id="bookTitle" type="text" value="&lt;?php echo $bookInformation-&gt;bookTitle; ?&gt;" /&gt;&lt;br />
  
    <label for="author">Author:  </label><br />
   &lt;input name='author' id="author" value="&lt;?php echo $bookInformation-&gt;author; ?&gt;" /&gt;&lt;br />
  
      
   <label for="ISBN">ISBN </label> <br />
   &lt;input name='ISBN' id="ISBN" type='text' value="&lt;?php echo $bookInformation-&gt;isbn; ?&gt;" /&gt;&lt;br />
      
    <label for="description">Description:<label><br />
    &lt;textarea rows="10" cols="30" id="description" name="description" value="&lt;?php echo $bookInformation-&gt;description; ?&gt;"&gt;&lt;/textarea><br /><br />

      <label for="categoryID">Categories: </label> <br />
  
      <select name="categoryID" id="categoryID">
          <option value="">---- Please Select a Category ----</option>
       <option value="1">1. Arts & Photography</option>
     <option value="2">2. Children's Books</option>
     <option value="3">3. Computers & Technology</option>
     <option value="4">4. Science & Math</option>
       </select>

&lt;input id="submit" type="submit" value="Submit" /&gt;
  <br />
<br />
&lt;/form&gt;

  &lt;?php echo "<strong>Book ID</strong>: " . $bookInformation->bookID . "<br />"; ?&gt;
  &lt;?php echo "<strong>Book Author</strong>: " . $bookInformation->author . "<br />"; ?&gt;
  &lt;?php echo "<strong>Book Title</strong>: " . $bookInformation->bookTitle . "<br />"; ?&gt;
  &lt;?php echo "<strong>Book ISBN</strong>: " . $bookInformation->isbn . "<br />"; ?&gt;
  &lt;?php echo "<strong>Book Description</strong>: " . $bookInformation->description . "<br />"; ?&gt;
        &lt;?php echo "<strong>Book Category</strong>: " . $bookInformation->categoryID . "<br />"; ?&gt;
        
        <br />
         <br />
  &lt;?php echo "DELETE" ?&gt;
  &lt;?php echo anchor("dashboard/delete_books/$bookInformation->bookID", "Delete"); ?&gt;
        



&lt;?php
$this->load->view("footer_view");
?&gt;

Below are the two functions related to this application.

Code:
public function get_edit_books_form( $bookID="" ) {
  
  
  if (empty( $bookID )) {
   $bookID = $this->uri->segment(3, 0);
  }
  
  $this->load->model("BooksModel");
  $data['bookInformation'] = $this->BooksModel->get_books( $bookID );
  
  $this->load->view("edit_books_form_view", $data);
}

public function update_books() {
  
      
   $this->load->model("BooksModel");
   $this->BooksModel->update_books( $_POST );
   $this->session->set_flashdata('message', 'Books data updated.');
   redirect("dashboard/get_edit_books_form/" . $_POST['bookID']);
  

}
#2

[eluser]ojcarga[/eluser]
Do you mean when you click on this link right?
Code:
echo anchor_popup('dashboard/get_edit_books_form', 'Edit/Delete', $atts);

I guess you are not setting the bookID for that link, this way
Code:
echo anchor_popup('dashboard/get_edit_books_form'.$bookInformation->bookID, 'Edit/Delete', $atts);

Cause the function
Code:
public function get_edit_books_form( $bookID="" ) {
receive a parameter, so I guess you are loosing it. The way you have it right now you don't have the segment(3)
Code:
if (empty( $bookID )) {
   $bookID = $this->uri->segment(3, 0);
}
#3

[eluser]theif_of_always[/eluser]
Thanks ojcarga,

Yeah, that's right. When you click on the "edit/delete" it takes you to my edit form. Except,
it only targets the most recent entry. If you had 50 entries, it would still just target the lastest entry.

R you saying that I need to chance the parameters in the segment area?

C
#4

[eluser]Matalina[/eluser]
Code:
echo anchor_popup('dashboard/get_edit_books_form', 'Edit/Delete', $atts);

No you need to add in your Book id to the url of the anchor above

like:

Code:
echo anchor_popup('dashboard/get_edit_books_form/'.$book_id_here, 'Edit/Delete', $atts);
#5

[eluser]theif_of_always[/eluser]
Thanks Lab Assistant.

But, how do I enable so it inherits the bookid of the insert? If I put something like $bookID=2, then it would just always edit the bookid 2. How do I make it take the id of whatever the insert happened to be at that time?

Thanks again for your help.

#6

[eluser]InsiteFX[/eluser]
This uses the CodeIgniter Table Class
Code:
// Get an array of users from the database.
$data = $this->users->users();

// Set the table headings.
$this->table->set_heading('User Name', 'Email', 'Actions');

foreach ($data as $value => $key)
{
    // Build edit/delete action links.
    $actions = anchor("admin/users/edit/".$key['id']."/", "Edit") .
               anchor("admin/users/delete/".$key['id']."/", "Delete");

    // Add the new row to table.
    $this->table->add_row($key['username'], $key['email'], $actions);
}

This should give you an idea of how to do it.

#7

[eluser]Samus[/eluser]
[quote author="Matalina" date="1336513884"]
Code:
echo anchor_popup('dashboard/get_edit_books_form', 'Edit/Delete', $atts);

No you need to add in your Book id to the url of the anchor above

like:

Code:
echo anchor_popup('dashboard/get_edit_books_form/'.$book_id_here, 'Edit/Delete', $atts);
[/quote]
You get it from the database the same way you call the other database info




Theme © iAndrew 2016 - Forum software by © MyBB