0

at the moment i've coded out like

<div class="row">
 <div class="col-lg-12">
  <table id="usertable" class="table table-bordered table-hover text-center">
   <thead>
    <th class="col-lg-1 text-center">User ID</th>
    <th class="col-lg-4 text-center">Username</th>
    <th class="col-lg-4 text-center">Password</th>
    <th class="col-lg-2 text-center">Role</th>
   </thead>
   <tbody>
   <?php
    require('dbconnectmssql.php');
    $sql = "select [User_ID],[user_decoded],[pass_decoded],[permission] from [rfttest].[dbo].[users]";
    $query = sqlsrv_query ($conn , $sql);
    if($query === false)
    {die( print_r( sqlsrv_errors(), true));}
    while($row = sqlsrv_fetch_array( $query, SQLSRV_FETCH_NUMERIC))
    {
     echo "<tr>";
     foreach($row as $x => $a)
     {
      echo "<td>".$a."</td>";
     }
      echo "<td>";
      echo "<a href='#' ><span class='glyphicon glyphicon-wrench' aria-hidden='true'></span></a>";
      echo "<a href='usercontrol.php?del=$row[0]'>";
      echo "<span class='glyphicon glyphicon-trash' aria-hidden='true'></span>";
      echo "</a>";
      echo "</td>";
      echo "</tr>";
     }
     ?>
    </tbody>
   /table>
  </div>
 </div>

it's all about query out and show how many user in the table.

  • I've done the delete-record by link to PHP file and $_GET data (maybe improve later if have another solution that you will suggest )

Another things that i want to do is

  • Edit specific record without redirected to another page

My idea for right now is hidden form that popup after click edit such as i've click then form pop up with data record that stored and user can edit it and save it by submit to PHP file and then redirect back to this page

something like : Contain form within a bootstrap popover? post

<a href="#" id="popover">the popover link</a>
<div id="popover-head" class="hide">
  some title
</div>
<div id="popover-content" class="hide">
  <!-- MyForm -->
</div>

but i still can't figured out

  • How can i code out to make the link to open the specific popover-head/content maybe popover-head/content must be contain in id or something ?
  • What about PHP
  • What about JS/JQ also

Any solution what i just want only something to edit specific record that echo out

Sorry for my bad English

Thanks

Community
  • 1
  • 1

1 Answers1

1

You likely want to use AJAX for this.

This looks so painful to me - and if it worked a google spidering would delete all users on the page:

}
  echo "<td>";
  echo "<a href='#' ><span class='glyphicon glyphicon-wrench' aria-hidden='true'></span></a>";
  echo "<a href='usercontrol.php?del=$row[0]'>";
  echo "<span class='glyphicon glyphicon-trash' aria-hidden='true'></span>";
  echo "</a>";
  echo "</td>";
  echo "</tr>";
 }

It could be written

} ?>
 <td>
 <a href='#' ><span class='glyphicon glyphicon-wrench' aria-hidden='true'></span></a>
 <a class="del" href='#' data-userid='<?PHP echo row["User_ID"]; ?>'>
 <span class='glyphicon glyphicon-trash' aria-hidden='true'></span>
 </a>
</td>
</tr>
<?PHP } ?>

And then

$(function() {
  $(".del").on("click",function(e) {
    e.preventDefault(); stop the page from reloading
    var id=$(this).data("userid");
    $.get("usercontrol.php?del="+id,function() {
      alert(id + "deleted");
    });
  });
});

To edit

  • Popup a form with the data using .show() and .hide()
  • change the data
  • AJAX the changes on submit - be sure to use preventDefault to stop actual submission $("form").on("submit",function(e) { e.preventDefault(); $.post("save.php",$(this).serialize(),function(data) { alert("saved"); $("#formDiv").hide() });});
  • show the result
  • close the popup
mplungjan
  • 169,008
  • 28
  • 173
  • 236
  • Thanks for deleting record suggestion // But what about edit specific record ? – Trin Pongtaman Aug 25 '15 at 07:52
  • See update. You should be able to fill a form with data from the link like I did with data-userid – mplungjan Aug 25 '15 at 08:19
  • i'm trying to apply it into my project give me a min. maybe hours lol . I've one question is it necessary to use [user_id] instead [0] ? – Trin Pongtaman Aug 25 '15 at 08:24
  • I do not do PHP. You need to have `data-userid="whatever will identify your user enough to delete/edit him/her"` – mplungjan Aug 25 '15 at 08:31
  • might be silly question (because this is my first time on JQ/AJAX I've no idea how to code save.php file (it's not like as deleting that you show me .get by link what is difference). any suggestion ? – Trin Pongtaman Aug 25 '15 at 08:49
  • the ajax POST does the same as the ajax GET except it can handle more data and the result is in the $_POST instead of the $_GET. Here is an example which I googled for you since I as I mentioned do not do much PHP http://stackoverflow.com/questions/16507731/update-user-details-sql-server-2008-sqlsrv – mplungjan Aug 25 '15 at 08:55
  • ok thanks i'm done applying and it's work but still try to figured out how to code php lol – Trin Pongtaman Aug 25 '15 at 10:09