I just try to make simple content change in my html page from mysql with php.

This is my sql I want to use and I have "Next Post" button, what would be the best way to make the button change the id to 2,3,4,5.. and then on then on.. Just cant get this figure out, I don't know what's better to use here Get or how do I do it couldn't find answer

$sql = "SELECT *  FROM `posts` WHERE `id` = 1";

1 Answers

Community On Best Solutions

You can use a variable for id and use a post from your HTML where when you press the button it updates the number in the id variable. I have not tested this but maybe something like this?

$$servername = **********
$server_username = ***************
$server_password = ****************
$dbName = *****************

$id = 1;

//Make Connection
$conn = new mysqli($servername, $server_username, $server_password, $dbName);
//Check Connection
    die("Connection Failed". mysqli_connect_error());

$sql = "SELECT *  FROM `posts` WHERE .$id"


<button type="button" onClick="<?php $id++ ?>">+</button>

etc... just have something in your HTML which will update the 'id' value or do something in the HTML code above that increments the variable and. And you can just place the php code in the same file as the html code without using post or you can alter it to use post if you would like.