0

I've seen multiple pages regarding my issue. The closest I found was this:

Passing data to a bootstrap modal

But I think my issue is slightly different. I have pulled MySQL data and displayed it within a table via PHP. I need to pull the row data via href into a bootstrap modal page.

On my edit.php page, here is the first line of the returned data, where the EDIT button and href is located:

 echo "<tr><td><a class=\"btn btn-primary btn-mini\" data-toggle=\"modal\"   href=\"#myEditModal\" data-project-id=\"$Row[pk_tId]\">Delete/Edit</a></td>";

Please disregard the lack of closing tags. It's in the code, just not displayed here.

I'm guessing I need to get $Row[pk_tId] and pass that into the modal, and then run a MySQL statement off pk_tId so that I can pull the data into the modal input fields. My question is: How do I do that? I would like to just use javascript. No ajax for now. I'll learn that later.

So please, how do I get $Row[pk_tId] into the modal shown here:

 <div class="modal hide fade" id="myEditModal" tabindex="-1" role="dialog" aria-labelleby="myModalLabel" aria-hidden="true">
 <form class="well-small" action="edit.php" method="POST" id="modalForm" name="modalForm">
 <?php
    if (isset($_GET['pk_tId'])){
        $id = $_GET['pk_tId'];
        $res = mysql_query("SELECT * FROM mytable WHERE pk_tId ='" .$id. "'");
        $selection = mysql_fetch_array($res);
    }
?>
         <label>Group</label>
    <input type="text" id="group" name="group" value="<?php echo $selection[mygroup]; ?>" /> 

Please disregard the closing form tags. They are there. I just didn't want to display a lot of unnecessary code.

Community
  • 1
  • 1
HoodCoderMan
  • 103
  • 7
  • 26
  • I did answer but thinking better, I have to ask: the modal is a form submission? I mean, there is a page reload? Or the modal is just a plain html content in this same page? Can't figure it out without seeing all the code. – lsouza Aug 09 '13 at 17:44
  • Using the code you provided below, I need to pass the pk_tId, which is a column in the actual database. Where you put this: data-project-id=\"".$_GET['id']."\" How do I get this in there: $Row[pk_tId]; I tried this: data-project-id=\"$Row[pk_tId]\" but that doesn't work. – HoodCoderMan Aug 09 '13 at 18:21

1 Answers1

0

How about passing it as a $_GET parameter?

<?php
    if (isset($_GET['pk_tId'])){
        $id = $_GET['pk_tId'];
        $res = mysql_query("SELECT * FROM mytable WHERE pk_tId ='" .$id. "'");
        $selection = mysql_fetch_array($res);
    }
?>
<form class="well-small" action="edit.php?id=<?php echo $id ?>" method="POST" id="modalForm" name="modalForm">

Then your first line of edit.php would be:

echo "<tr><td><a class=\"btn btn-primary btn-mini\" data-toggle=\"modal\"   href=\"#myEditModal\" data-project-id=\"".$_GET['id']."\">Delete/Edit</a></td>";
lsouza
  • 2,448
  • 4
  • 26
  • 39