質問: 245.356.134.22に変更したいのですが 私が学ぶ必要がある何かがあるかどうか私に知らせてください。ありがとうございました
回答: データベーステーブルからデータを取得する <?php $results = $wpdb->get_results( "select * from $table_name"); // query to fetch data from database table and storing in $results if(!empty($results)) // checking if $results have some values or not { echo "<table width='100%' border='0'>"; // adding <table> and <tbody> tag outside foreach loop so that it wont create again and again echo "<tbody>"; foreach($results as $row){ $userip = $row->user_ip; //putting the user_ip field value in variable to use it later in update query echo "<tr>"; // adding rows of table inside foreach loop echo "<th>id</th>" . "<td>" . $row->id . "</td>"; echo "</tr>"; echo "<td colspan='2'><hr size='1'></td>"; echo "<tr>"; echo "<th>user ip</th>" . "<td>" . $row->user_ip . "</td>"; //fetching data from user_ip field echo "</tr>"; echo "<td colspan='2'><hr size='1'></td>"; echo "<tr>"; echo "<th>post id</th>" . "<td>" . $row->post_id . "</td>"; echo "</tr>"; echo "<td colspan='2'><hr size='1'></td>"; echo "<tr>"; echo "<th>time</th>" . "<td>" . $row->time . "</td>"; echo "</tr>"; echo "<td colspan='2'><hr size='1'></td>"; } echo "</tbody>"; echo "</table>"; } ?> note: change your data fetching format according to your need (table structure) if条件で時間フィールドを更新する <?php if($userip==245.356.134.22){ //checking if user_ip field have following value $wpdb->update( $table_name, array( 'time' => 'your new time' // entring the new value for time field ), array('%d') // specify the datatype of time field ); } ?> アップデート データベースに挿入しようとしているipが既に存在するかどうかを確認したい場合は、次のように確認してください。<?php global $wpdb,$ip; $results = $wpdb->get_results( "select user_ip from $table_name"); //query to fetch record only from user_ip field $new_ip = 245.356.134.22; //new ip address storing in variable if(!empty($results)) { foreach($results as $row){ $old_ip = $row->user_ip; // putting the value of user_ip field in variable if($new_ip==$old_ip){ // comparing new ip address with old ip addresses $ip = 'already exist'; // if ip already exist in database then assigning some string to variable } } } if($ip = 'already exist'){ // checking if variable have some string (it has some string only when if ip already exist in database as checked in if condition by comparing old ips with new ip) //insert query according to ip already exist in database }else{ //insert query according to ip doesn't exist in database } ?>