javascript - How to post info form wp sql into js -


am new developing , trying learn self doing different things.right trying wordpress pluging can create database , insert , delete info it.after catch info sql clicking btn name="chooseid" , js code sql row info save on , code. done inserting , deleting section facing problem getting info the selected name="chooseid" js. advice please how solve issue , code run.

best regard's

 <?php     /*     * plugin name: reloader1     * description: reloader of pages     * version: 1.0     * author: test     *     */     // attach bootstrap      function xobamax_resources() {         wp_enqueue_style('bootstrap', 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css');         wp_enqueue_style('style', get_stylesheet_uri());         wp_enqueue_script( 'bootstrap-js', 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js', array('jquery'), '3.3.4', true );     }     add_action('admin_init', 'xobamax_resources');      // create db     function jal_install()     {         global $wpdb;         global $jal_db_version;          $table_name = $wpdb->prefix . 'reloaderdb2';          $charset_collate = $wpdb->get_charset_collate();          $sql = "create table $table_name (             id mediumint(9) not null auto_increment,             refresh_time int(16) not null,             br_start int(16) not null,             br_end int(16) not null,             br_domain varchar(55) not null,             lu_start int(16) not null,             lu_end int(16) not null,             lu_domain varchar(55) not null,             main_domain varchar(55) not null,             primary key  (id)         ) $charset_collate;";          require_once(abspath . 'wp-admin/includes/upgrade.php');         dbdelta($sql);          add_option('jal_db_version', $jal_db_version);     }      register_activation_hook(__file__, 'jal_install');        // load scripts       /** step 2 (from text above). */     add_action('admin_menu', 'my_plugin_menu');      /** step 1. */     function my_plugin_menu()     {         add_options_page('my plugin options', 'reloader', 'manage_options', 'reloader', 'my_plugin_options');     }           // insert info db       if ($_post['save-data'] === 'update_db') {          global $wpdb;          $refresh_time = $_post['refresh_time'];         $br_start = $_post['br_start'];         $br_end = $_post['br_end'];         $br_domain = $_post['br_domain'];         $lu_start = $_post['lu_start'];         $lu_end = $_post['lu_end'];         $lu_domain = $_post['lu_domain'];         $m_domain = $_post['m_domain'];          $table_name = $wpdb->prefix . 'reloaderdb2';         $args = array(             'refresh_time' => $refresh_time,             'br_start' => $br_start,             'br_end' => $br_end,             'br_domain' => $br_domain,             'lu_start' => $lu_start,             'lu_end' => $lu_end,             'lu_domain' => $lu_domain,             'main_domain' => $m_domain         );         $wpdb->insert($table_name, $args );      }       /** step 3. */     function my_plugin_options()     {          if (!current_user_can('manage_options')) {             wp_die(__('you not have sufficient permissions access page.'));         }          echo '<div class="wrap">'; ?>          // showing database result table         <table class="table table-bordered table-striped table-hover table-responsive">             <thead>             <tr>                 <th>                     id                 </th>                 <th>                     reloading time                 </th>                 <th>                     breakfast starting time                 </th>                 <th>                     breakfast ending time                 </th>                 <th>                     breakfast domain link                 </th>                 <th>                     lunch starting time                 </th>                 <th>                     lunch ending time                 </th>                 <th>                     lunch domain link                 </th>                 <th>                     main domain                 </th>                 <th>                    action                 </th>                 <th>                     select                 </th>             </tr>             </thead>             <?php              global $wpdb;              $table_name = $wpdb->prefix . 'reloaderdb2';             $result = $wpdb->get_results( "select * $table_name");             foreach ( $result $print )   { ?>                  <tbody>                 <tr>                     <td>                         <?php echo $print->id; ?>                     </td>                     <td>                         <?php echo $print->refresh_time; ?>                     </td>                     <td>                         <?php echo $print->br_start; ?>                     </td>                     <td>                         <?php echo $print->br_end; ?>                     </td>                     <td>                         <?php echo $print->br_domain; ?>                     </td>                     <td>                         <?php echo $print->lu_start; ?>                     </td>                     <td>                         <?php echo $print->lu_end; ?>                     </td>                     <td>                         <?php echo $print->lu_domain; ?>                     </td>                     <td>                         <?php echo $print->main_domain; ?>                     </td>                     <td>                         <form method="post">                             <?php wp_nonce_field( 'my_delete_event_' . $print->id ); ?>                             <input type="hidden" name="action" value="my_delete_event">                             <input type="hidden" name="deleteeventid" value="<?php echo $print->id; ?> ">                             <input type="submit" class="delete" value="delete" />                         </form>                      </td>                     <td>                         <form method="post">                             <?php wp_nonce_field( 'my_event_' . $print->id ); ?>                             <input type="hidden" name="action" value="my_event">                             <input type="hidden" name="chooseid" value="<?php echo $print->id; ?> " onclick="countdown()">                             <input type="submit" class="select" value="select" />                         </form>                     </td>                 </tr>                  </tbody>             <?php };               ?>          </table>         // fill reloader info form         <form action="" method="post">             <input type="hidden" value="update_db" name="save-data">             <fieldset>                 <h2>reloading time</h2>                 <label for="time">type after how many minutes page refresh:</label>                 <input type="number" id="refresh_time" name="refresh_time">             </fieldset>             <br>             <fieldset>                 <h2>breakfast period</h2>                 <label for="breakfast_start">type when breakfast period start:</label>                 <input type="number" id="br_start" name="br_start"><br>                 <label for="breakfast_end">type when breakfast period end:</label>                 <input type="number" id="br_end" name="br_end"><br>                 <label for="breakfast_domain">past in breakfast domain page:</label>                 <input type="text" id="br_domain" name="br_domain"><br>             </fieldset>             <br>             <fieldset>                 <h2>lunch period</h2>                 <label for="lunch_start">type when lunch period start:</label>                 <input type="number" id="lu_start" name="lu_start"><br>                 <label for="lunch_end">type when lunch period end:</label>                 <input type="number" id="lu_end" name="lu_end"><br>                 <label for="lunch_domain">past in lunch domain page:</label>                 <input type="text" id="lu_domain" name="lu_domain"><br>             </fieldset>             <br>             <fieldset>                 <h2>main domain</h2>                 <label for="main_domain">past in domain page:</label>                 <input type="text" id="m_domain" name="m_domain">             </fieldset>             <br>             <input type="submit" value="submit" name="submit"                    style="padding: 8px;background:#00b0e8;color: #000;width: 200px;" >         </form><br>           </div>          <?php     }          // remove event specified eventid          if (!empty($_post['deleteeventid'])) {             global $wpdb;             $id = $_post['deleteeventid'];             $wpdb->delete( $wpdb->prefix . 'reloaderdb2',                 [ 'id' => $id ],                 [ '%d' ] );          }       // select event info run js       if (!empty($_post['chooseid'])) {         global $wpdb;         $id = $_post['chooseid'];         $table_name = $wpdb->prefix . 'reloaderdb2';         $result = $wpdb->get_results( "select * $table_name");         var_dump($result);     foreach ( $result $print ) { ?>         <script>              function countdown() {                 console.log(1);                 var refresh= <?php echo $print->refresh_time; ?>                 var bstart=<?php echo $print->br_start; ?>                 var bend=<?php echo $print->br_end; ?>                 var bdomain=<?php echo $print->br_domain; ?>                 var lstart=<?php echo $print->lu_start; ?>                 var lend=<?php echo $print->lu_end; ?>                 var ldomain=<?php echo $print->lu_domain; ?>                 var mdomain=<?php echo $print->m_domain; ?>                 var countdown = refresh;                  setinterval(function () {                      if (countdown == 0) {                         var date = new date();                         var nowhour = date.gethours();                         if(nowhour >=bend && nowhour<=bstart){                             window.location.href = bdomain;                          }                         else if(nowhour >=lend && nowhour<=lstart){                             window.location.href = ldomain;                          }                         else{                             window.location.href = mdomain;                          }                     }                     countdown--;                  }, 1000);              }           </script>         <?php     }     }      ?> 


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -