On click submit button next and previous record in php mysql

Description

Onclick submit button with form next and previous record in php mysql. How to move next and previous record in php mysql with submit button show next post record mysql with php and mysql. Dynamic Next and Previous submit Buttons with PHP and MySQL fetch record according to id

Next and Previous submit Buttons and go to next page with PHP and MySQL fetch record according to id

Pagination next and previous record in php mysql

if (isset($_POST['id'])) {

    $tmp = array_keys($_POST['id']);

    $curid = intval($tmp[0]);

 

 

    // Select contents from the selected id

    $sql = "SELECT * FROM oflinetestresult WHERE id={$curid}";

    $result = mysql_query($sql);

    if (mysql_num_rows($result)>0) {

        $info = mysql_fetch_assoc($result);

    } else {

        die('Not found and fetch');

    }

 

 

    // Next id

    $sql = "SELECT id FROM oflinetestresult WHERE id > {$curid} LIMIT 1";

    $result = mysql_query($sql);

    if (mysql_num_rows($result)>0) {

        $nextid = mysql_result($result,0);

    }

 

 

 

    // Prev id

    $sql = "SELECT id FROM oflinetestresult WHERE id<{$curid} LIMIT 1";

    $result = mysql_query($sql);

    if (mysql_num_rows($result)>0) {

        $previd = mysql_result($result,0);

    }

} else {

    // No form has been submitted so use the lowest id and grab its info back 

    $sql = "SELECT * FROM oflinetestresult WHERE id > 0 LIMIT 1";

    $result = mysql_query($sql);

    if (mysql_num_rows($result)>0) {

        $info = mysql_fetch_assoc($result);

    }

if (isset($info)) {

    $content = '<pre>'.print_r($info,true).'</pre>';

} else {

    $content =  'Nothing in the db :(';

}

?>

 

<html>

<body>

<?php echo $content; ?>

<div style="color:#000000">

<h3>Info</h3>

<form method="post" style="color:#000000">

<input type="text" name="name" autofocus="autofocus" id="xax" style="color:#000000" />

<?php if (isset($previd)) { ?>

pre

<input type="submit" name="id[<?php echo $previd?>]" value="prev">

<?php } ?>

<?php if (isset($nextid)) { ?>

Next

<input type="submit" name="id[<?php echo $nextid?>]" value="next">

<?php } ?>

</form>

<h3>Info</h3>

</div>

</body>

</html>