[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);
}
?>
Here is the "get_edit_books_form" page
Code:
<?php
echo $this->session->flashdata('message');
echo validation_errors();
$id = array('id' => 'BookForm');
echo form_open('dashboard/update_books', $id);
$bookInformation = $bookInformation->row();
?>
<?php echo "EDIT/UPDATE" ?>
<br />
<br />
<input name="bookID" type="hidden" value="<?php echo $bookInformation->bookID; ?>" />
<label for="bookTitle">Book Title</label><br />
<input name="bookTitle" id="bookTitle" type="text" value="<?php echo $bookInformation->bookTitle; ?>" /><br />
<label for="author">Author: </label><br />
<input name='author' id="author" value="<?php echo $bookInformation->author; ?>" /><br />
<label for="ISBN">ISBN </label> <br />
<input name='ISBN' id="ISBN" type='text' value="<?php echo $bookInformation->isbn; ?>" /><br />
<label for="description">Description:<label><br />
<textarea rows="10" cols="30" id="description" name="description" value="<?php echo $bookInformation->description; ?>"></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>
<input id="submit" type="submit" value="Submit" />
<br />
<br />
</form>
<?php echo "<strong>Book ID</strong>: " . $bookInformation->bookID . "<br />"; ?>
<?php echo "<strong>Book Author</strong>: " . $bookInformation->author . "<br />"; ?>
<?php echo "<strong>Book Title</strong>: " . $bookInformation->bookTitle . "<br />"; ?>
<?php echo "<strong>Book ISBN</strong>: " . $bookInformation->isbn . "<br />"; ?>
<?php echo "<strong>Book Description</strong>: " . $bookInformation->description . "<br />"; ?>
<?php echo "<strong>Book Category</strong>: " . $bookInformation->categoryID . "<br />"; ?>
<br />
<br />
<?php echo "DELETE" ?>
<?php echo anchor("dashboard/delete_books/$bookInformation->bookID", "Delete"); ?>
<?php
$this->load->view("footer_view");
?>
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']);
}