user1536365
user1536365

Reputation: 25

Twitter Bootstrap - Passing a unique ID to a Modal

I have searched a lot and am still having some trouble passing a Unique Id to a Value and then using that ID for a PHP MySQL Query to get the book info.

I currently am passing the unique ID to the Modal and Displaying it through an input type text. I am just having a hard time figuring out how to put the id into a php Variable

Here is my HTMl/PHP code

                    echo '<a data-toggle="modal" data-id="' . $book_id .'" title="Add this item" class="open-AddBookDialog btn btn-primary" href="#addBookDialog">View Info</a>';?>

        <!-- Modal -->
                <div class="modal hide" id="addBookDialog">
                    <div class="modal-header">
                        <button class="close" data-dismiss="modal">×</button>
                        <h3>Book Info</h3>
                    </div>
                    <div class="modal-body">
                        <p>some content</p>
                        <?php 
                        echo $test = '<input type="text" name="bookId" id="bookId"/>';

                            $book_info = get_book_info($book_id);

                            while($row1 = mysqli_fetch_array($book_info))
                            {
                                $email = $row['email'];
                                echo "<p><strong>Title: </strong>" . $row1['title'] . "</p>";
                                echo "<p><strong>Author: </strong>" . $row1['author'] . "</p>";
                                echo "<p><strong>Edition: </strong>" . $row1['edition'] . "</p>";
                                echo "<p><strong>ISBN: </strong>" . $row1['isbn'] . "</p>";
                                echo "<p><strong>Price: </strong>" . $row1['price'] . "</p>";
                                echo "<p><strong>Seller's Name: </strong>" . $row1['name'] . "</p>";
                                echo "<p><strong>Seller's E-mail: </strong><a href='mailto:$email'>$email</a></p>";
                            }?>
                    </div>
                    <div class="modal-footer">
                        <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
                    </div>
                </div>

here is my jquery

        $(document).on("click", ".open-AddBookDialog", function () {
         var myBookId = $(this).data('id');
         $(".modal-body #bookId").val( myBookId );
    });

Upvotes: 0

Views: 2375

Answers (2)

StenW
StenW

Reputation: 2004

You could do something like this by javascript/coffee script.

($ "a[data-toggle=modal]").click ->
target = ($ @).attr('data-target')
url = ($ @).attr('href')
($ target).load(url)

URL = unique ID

Upvotes: 0

Eddie Jaoude
Eddie Jaoude

Reputation: 1708

You need to echo the value:

data-id="<?php $book_id ?>"

Use this instead:

data-id="<?php echo $book_id; ?>"

Upvotes: 1

Related Questions