How to fetch Data in WordPress using MySQLi or $wpdb

Question

I have custom table like this:

useraw

1. id (Primary*)
2. user_ip
3. post_id
4. time

I am inserting data in the table using

$wpdb->insert($table_name , array('user_ip' => $user_ip, 'post_id' =>
$postID, 'time' => $visittime),array('%s','%d', '%d') );

There are four rows I inserted using this code:

id                  :        245
user_ip             :        245.346.234.22
post_id             :        24434
time                :        255464

id                  :        345
user_ip             :        245.346.234.22
post_id             :        23456
time                :        23467

id                  :        567
user_ip             :        245.346.234.22
post_id             :        57436
time                :        5678

id                  :        234
user_ip             :        245.356.134.22
post_id             :        2356
time                :        45678

I want to learn how to use MySQL queries in WordPress. So here are my questions:

  1. How to display all the data of table?
  2. How to replace data if condition matched. Like I want change the time where user_ip = 245.356.134.22

Please let me know if there is something I must need to learn.

Thank You

0
Ramesh Pardhi 2 years 2020-12-28T05:11:00-05:00 0 Answers 4 views 0

Leave an answer

Browse
Browse