Advertisement
Guest User

Untitled

a guest
Aug 5th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. <?php
  2. $sdbhost = 'dbhost';
  3. $dbuser = 'dbuser';
  4. $dbpass = 'dbpassword';
  5. $conn = mysqli_connect($dbhost, $dbuser, $dbpass, $dbuser);
  6. if (!$conn){
  7. die('cannot connect to mysql');
  8. }
  9.  
  10.  
  11.  
  12. $query = "SELECT `entry1` FROM `$selectedTable` WHERE 1 LIMIT 0, 30 ";
  13.  
  14. if ($result = mysqli_query($conn , $query)) {
  15.  
  16. $num = mysqli_num_rows($result);
  17.  
  18. for ($i = 0; $i < $num; $i++){
  19.  
  20. $myArray[] = mysqli_fetch_assoc($result);
  21.  
  22. }
  23. echo "<div class = 'dataSelect'>";
  24.  
  25. foreach( $myArray AS $key=>$data ){
  26.  
  27. echo "<input type='checkbox' name = '". $data['entry1'] . "' value = '".$data['entry1']."'> " .$data['entry1']. "<br/>";
  28. }
  29.  
  30. echo "</div>";
  31.  
  32.  
  33. }else{
  34. echo "Something wrong";
  35. }
  36.  
  37.  
  38. ?>
  39.  
  40. var checkedAttr = [];
  41.  
  42. //Everytime checkbox is changed
  43. $('input:checkbox').change(function(){
  44. //Everytime Checkbox is checked
  45. if ($(this).is(':checked')) {
  46. $(' input:checkbox').each(function(i, item){
  47. if($(item).is(':checked')){
  48. //Add into Array
  49. checkedAttr.push($(item).val());
  50. }
  51. });
  52. }
  53. var jsonString = JSON.stringify(checkedAttr);
  54. console.log(jsonString);
  55.  
  56. // AJAX to PHP
  57. $.ajax({
  58. type: "POST",
  59. url: "dataToGraph.php",
  60. data: { data : jsonString },
  61. cache: false,
  62. success: function(){
  63. alert('Okay');
  64. }
  65. });
  66. //Prevent more than two rows selected
  67. if ($('input:checkbox:checked').length >= 2) {
  68. $(".dataSelect").fadeOut('slow');
  69. }
  70. });
  71.  
  72. <?
  73. if(isset($_POST['data'])){
  74. $data = $_POST['data'];
  75. print_r($data);
  76. foreach($data as $d){
  77. echo $d;
  78. }
  79. }else{
  80. echo'SOMETHING IS WRONG WITH THIS, DON'T BE SADDDD';
  81. }
  82. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement