Changing posts date

Im trying to change the date of every post after a specific date to an older, back in another year, but it seems that i get a specific result regarding a post with ID 214. I was wondering if this has to do with my code, or if this is a db issue.

Here’s my code. Thanks everyone in advance for helping.

$servername = "localhost";
$username = "user";
$password = "pass";
$dbname = "db";

$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);

$sql = "SELECT * FROM dm_posts where post_date > '2017-04-30'";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    echo "<table><tr><th>ID</th><th>Post Title</th></tr>";
    // output data of each row
    while($row = $result->fetch_assoc()) {
        echo "<tr><td>".$row["ID"]."</td><td>".$row["id"]." ".$row["post_title"]."</td></tr>" ;
$idd = $row["ID"];
$int= rand(1388534400,1418342400);
$futuredate = date("Y-m-d H:i:s",$int);
$query1 = "UPDATE dm_posts SET post_date = '".$futuredate."' where post_date > '2017-04-30' and id = '".$idd."'";
$result1 = $conn->query($query1);
    echo "</table>";

} else {
    echo "All IS DONE";

Read more here: Changing posts date

Leave a Reply

Your email address will not be published. Required fields are marked *