Guest User

Untitled

a guest
Feb 17th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. <table width="100%" border="0" cellspacing="0" cellpadding="0">
  2. <thead>
  3. <tr>
  4. <th>id</th>
  5. <th>nome</th>
  6. <th>botao</th>
  7. </tr>
  8. </thead>
  9. <tbody>
  10. <?php $tab = pg_query($db,"select id, nome from tabela"); while($tabRow = pg_fetch_assoc($tab)){ ?>
  11. <form>
  12. <tr>
  13. <td><?php echo $tabRow['id'];?></td>
  14. <td><?php echo $tabRow['nome'];?></td>
  15. <td><button type="button" id="<?php echo $tabRow['id'];?>" name="btn" onclick="btn(this)">consultar</button></td>
  16. </tr>
  17. </form>
  18. <?php } ?>
  19. </tbody>
  20. </table>
  21. <div id="mostra"></div>
  22. <br />
  23. <!-- resultado a ser mostrado -->
  24. <form>
  25. <input type="id" name="id" value=""<br />
  26. <input type="nome" name="nomr" value=""<br />
  27. <img id="imagem" src=""/>
  28. </form>
  29.  
  30. <script>
  31. function btn(e){
  32. var txt = $(e).attr('id');
  33. $.ajax({
  34. type: 'post',
  35. url: 'tabela.php',
  36. data: {id: txt},
  37. beforeSend: function() { $("#loader").show(); },
  38. success: function(data) { $("#loader").hide(); }
  39. })
  40. .done(function(data){
  41. $("#mostra").html(data);
  42. //$("#form")[0].form.reset();
  43. });
  44. }
  45. </script>
  46.  
  47. if(isset($_POST['id'])){
  48.  
  49. $sql = pg_query($db,"select id, nome, encode(lo_get(imagem),'base64') as imagem, extensao from tabela where id = ".$_POST['id']."");
  50. $sqlRow = pg_fetch_assoc($sql);
  51.  
  52. echo '<script>
  53. $(function(){
  54. $("#id").val("'.$sqlRow ['id'].'");
  55. $("#nome").val("'.$sqlRow ['nome'].'");
  56. $("#imagem").attr("src","data:image/'.$sqlRow ['extensao'].';base64,'.$sqlRow ['imagem'].'");
  57. });
  58. </script>';
  59. }
Add Comment
Please, Sign In to add comment