php - Sending variables to Bootstrap modal -
here php function:
function displayrecords(){ $sql = "select * mytable"; $queryresult = @mysql_query($sql) or die (mysql_error()); // more code...
at point, function prints out retuned data in table:
echo "<table class='table table-striped table-bordered table-hover'>\n"; while(($row = mysql_fetch_assoc($queryresult)) !== false) {
and here issue begins:
echo "<tr><td><a class=\"open-editrow btn btn-primary btn-mini\" data-toggle=\"modal\" href=\"myeditmodal\" id=\"".$row[pk_tid]."\" title=\"edit row\" \">delete/edit</a></td>";
there more printed td
tags after this, issue transferring id modal window. told done straight php , without javascript or ajax.
this code looks in modal:
<div class="modal hide fade" id="myeditmodal" tabindex="-1" role="dialog" aria-labelleby="mymodallabel" aria-hidden="true"> <div class="modal-body"> <?php $id = "<input type=\"text\" name=\"groupid\" id=\"groupid\" value=\"\" />"; $sql = "select resgroup restable pk_tid = '" . $id . "'"; $result = mysql_query($sql);
as notice, $sql
reading $id
input tag, , therefore, cannot find id in database, , returns nothing. know starts anchor tag inside echoed table above.
i need utilize $_get
(or post
) in anchor tag, not know put it. i'm guessing should go in id=\"".$row[pk_tid]."\"
, how when php being used in id?
i visual person, if provide example, grateful.
you need bit javascript manipulate modal depends on button clicked. think solution you.
first, supposed there form inside modal , submit selected id
. modal body should this:
<div class="modal-body"> <form action="//your/path/to/php" method="post"> <input type="hidden" name="selected_id" id="selected_id" /> <input type="submit" name="commit" value="confirm action?" /> </form> </div>
second, think should remove data-toggle
property buttons, add data-*
property hold id
, use explicit javascript call show modal bit update.
a button should echo
echo "<tr><td><a class=\"open-editrow btn btn-primary btn-mini\" data-id=\"".$row[pk_tid]."\" title=\"edit row\" \">delete/edit</a></td>";
the javascipt
$('.open-editrow').click(function(){ var selected_id = $(this).attr('data-id'); $('#myeditmodal #selected_id').val(selected_id); $('#myeditmodal').modal('show'); });
now, in php file declared inside form in modal - receives post data, can var_dump
$_post
.
Comments
Post a Comment