Advertisement
Guest User

Untitled

a guest
Apr 2nd, 2016
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. <?php
  2.  
  3. $DB_host = "localhost";
  4. $DB_user = "root";
  5. $DB_pass = "";
  6. $DB_name = "test_shop";
  7. $options = array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf-8');
  8. try
  9. {
  10. $DB_con = new PDO("mysql:host={$DB_host};dbname={$DB_name}",$DB_user,$DB_pass);
  11. $DB_con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  12. $DB_con->exec('SET NAMES utf8');
  13. }
  14. catch(PDOException $e)
  15. {
  16. $e->getMessage();
  17. }
  18. ?>
  19. <html>
  20. <head>
  21.  
  22. <script src="http://code.jquery.com/jquery-latest.js"></script>
  23.  
  24. <script>
  25. $(function(){
  26. $('.number').click(function(a){
  27. a.preventDefault();
  28. var rno = $(this).data('id');
  29. $.ajax({
  30. type: "POST",
  31. url: "php_obrob.php",
  32. data: {id:rno}
  33. }).done(function( result )
  34. {
  35. $("#msg").html(result);
  36. });
  37. })
  38.  
  39. $('.cat').click(function(e){
  40. e.preventDefault();
  41. var idd = $(this).data('id');
  42. $.ajax({
  43. type: "POST",
  44. url: "new.php",
  45. data: {id:idd}
  46. }).done(function( result )
  47. {
  48. $("#product").html(result);
  49. });
  50. })
  51.  
  52. })
  53. </script>
  54. </head>
  55. <body>
  56.  
  57. <?php
  58. $stmt = $DB_con->query("SELECT * FROM `test_table`");
  59. while ($row = $stmt->fetch())
  60. {
  61.  
  62. echo
  63. '
  64. <li><a class="number" data-id="'.$row['number'].'" href="#">'.$row['name'].'</a></li>
  65. ';
  66.  
  67. }
  68.  
  69. ?>
  70.  
  71.  
  72. <br /><br />
  73. <div id="msg"> </div>
  74.  
  75. <div id="product"></div>
  76. </body>
  77. </html>
  78.  
  79.  
  80. php_obrob.php
  81.  
  82.  
  83. <?php
  84. $rno = $_POST['id'];
  85. ?>
  86. <?php
  87. /*В базе существует 1,2,3,4 number только разбираюсь почему передается только 1 во всех случаях?*/
  88. $stmt = $DB_con->query("SELECT * FROM `cat_woman` WHERE number='$rno'");
  89. while ($row = $stmt->fetch())
  90. {
  91.  
  92. echo
  93. '
  94. <li><a id="cat" data-id="'.$row['id'].'" href="#">'.$row['shop'].'</a></li>
  95. ';
  96.  
  97. }
  98.  
  99. ?>
  100.  
  101. new.php
  102.  
  103. <?php
  104.  
  105. $idd = $_POST['id'];
  106.  
  107. ?>
  108. <?php
  109. $stmt = $DB_con->query("SELECT * FROM `product` WHERE id_cat='$idd'");
  110. while ($row = $stmt->fetch())
  111. {
  112.  
  113. echo
  114. '
  115. <li><a class="numberss" data-id="'.$row['id'].'" href="#">'.$row['name'].'</a></li>
  116. ';
  117.  
  118. }
  119.  
  120. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement