Scoobeedo Cool
Scoobeedo Cool

Reputation: 111

How to move in a mysql table with ajax and php to the next and previous rows?

After the bad communication and unclear questions from yesterday from my side, I prepared something. I was the first time in a forum like this. It is tough, but good! I realized how professional the people in this forum. I know not one forum that comes near to your quality of informations!

I am not a sweet talker, this is fact! Here is the problem:

I connect to a mysql table but I can not go to the next and next and next row, the same for the previous records. I still dont understand it deeply. What is wrong on this code? I am really very curious to know it.

When I click on previous come "undefined objects."

When I skip next then comes only one record, and then it freeze. I guess that I am on the end of the table.

I was reading so many posts here, at least 50, but I did not get it. I just did not understand it.

nice greetings from Bangkok

+++

I dont use jquery commands. I use just json parse to fetch the data, but I get not a lot ;)

It is very basic. All what I want to do is get the previous and next rows. Always only one row. +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

function jsRecordNext()
{

    // ... the AJAX request is successful
    var updatePage = function( response ) {
    json_string = JSON.stringify(response);
    jsBlankArticle();
    jsShowArticle();
    };

    // ... the AJAX request fail
    var printError = function( req, status, err ) {
    alert("no luck");
    };

    // Create an object to describe the AJAX request
    var ajaxOptions = {
    url: 'nextarticle.php',
    dataType: 'json',
    success: updatePage,
    error: printError
    };

// Initiate the request!
$.ajax(ajaxOptions);

}

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

//previous row

<?php include "accesscontrol.php" ;?>

<?php

$result = mysql_query("SELECT * FROM articles WHERE id<$current_id ORDER BY id DESC LIMIT 1");
$current_id = mysql_insert_id();
$result = mysql_fetch_row($result);
echo json_encode($result);

?>

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

//next row

<?php include "accesscontrol+.php" ;?> // connection

<?php

$result = mysql_query("SELECT * FROM articles WHERE id>$current_id ORDER BY id ASC LIMIT 1");
$current_id = mysql_insert_id();
$result = mysql_fetch_row($resulat);
echo json_encode($result);

?>

++++++++++++++++++++++++++++++++

this is index.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US">
<META HTTP-Equiv="FileTransfer" Content="TransferEvent:url('Javascript:alert('%s')'); Transfer">

<head>
    <meta charset="UTF-8" />

    <title>SoB - Administration</title>

    <link rel="stylesheet" href="../wp-content/themes/Kuraya-Theme/style.css" tppabs="http://www.spiritofbushido.com/wp-content/themes/Kuraya-Theme/style.css">

    <link rel="pingback" href="http://www.spiritofbushido.com/xmlrpc.php">

    <script type="text/javascript" src="../wp-content/themes/Kuraya-Theme/js/scroll.js" tppabs="www.spiritofbushido.com/wp-content/themes/Kuraya-Theme/js/scroll.js"></script>

    <script type="text/javascript" src="../includes/jquery.js"></script>

    <script type="text/javascript" src="userinfo.0.0.1.min.js"></script>

    <link rel="alternate" type="application/rss+xml" title="Kuraya &raquo; Feed" href="http://www.scoobeedo.com/feed/" />
<link rel="alternate" type="application/rss+xml" title="Kuraya &raquo; Comments Feed" href="http://www.scoobeedo.com/comments/feed/" />
<link rel="alternate" type="application/rss+xml" title="Kuraya &raquo; Join Our E-mail List Comments Feed" href="http://www.scoobeedo.com/email-signup/feed/" />
<link rel='stylesheet' id='shadowbox-css-css'  href="../wp-content/uploads/shadowbox-js/src/shadowbox.css-ver=3.0.3.css" tppabs="http://www.scoobeedo.com/wp-content/uploads/shadowbox-js/src/shadowbox.css?ver=3.0.3" type='text/css' media='screen' />
<link rel='stylesheet' id='shadowbox-extras-css'  href="../wp-content/plugins/shadowbox-js/css/extras.css-ver=3.0.3.10.css" tppabs="http://www.scoobeedo.com/wp-content/plugins/shadowbox-js/css/extras.css?ver=3.0.3.10" type='text/css' media='screen' />
<link rel='stylesheet' id='contact-form-7-css'  href="../wp-content/plugins/contact-form-7/styles.css-ver=3.1.2.css" tppabs="http://www.scoobeedo.com/wp-content/plugins/contact-form-7/styles.css?ver=3.1.2" type='text/css' media='all' />
<script type='text/javascript' src="../../ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js-ver=3.3.2.js" tppabs="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js?ver=3.3.2"></script>
<script type='text/javascript' src="../wp-includes/js/comment-reply.js-ver=20090102.js" tppabs="http://www.scoobeedo.com/wp-includes/js/comment-reply.js?ver=20090102"></script>
<link rel='prev' title='東方古玩 蔵屋' href='http://www.scoobeedo.com/%e4%b8%ad%e6%96%87%e7%89%88/' />
<link rel='next' title='Sale 20% &#8211; 40% Off Entire Inventory Before Our Newshipment Arrived. Sales End April 30th.' href='http://www.scoobeedo.com/12131-2/' />
<link rel='canonical' href='http://www.scoobeedo.com/email-signup/' />
    <style type="text/css">.recentcomments a{display:inline !important;padding:0 !important;margin:0 !important;}</style>

    <script id="source" language="javascript" type="text/javascript">
        <!--

        var js_string;

        document.getElementById("recordWrite").disabled = true;

        function jsRecordPrevious()
            {
                // ... the AJAX request is successful
                var updatePage = function( response ) {
                    json_string = JSON.stringify(response);
                    jsBlankArticle();
                    jsShowArticle();
                };

                // ... the AJAX request fail
                var printError = function( req, status, err ) {
                    $( '#recordnumber').html( '-' );
                    alert("f p");
                };

                // Create an object to describe the AJAX request
                var ajaxOptions = {
                    url: 'previousarticle.php',
                    dataType: 'json',
                    success: updatePage,
                    error: printError
                };
                // Initiate the request!
                    $.ajax(ajaxOptions);
            }

        function jsRecordCurrent()
        {
            // ... the AJAX request is successful
            var updatePage = function( response ) {
                json_string = JSON.stringify(response);
                jsBlankArticle();
                jsShowArticle();
            };

            // ... the AJAX request fail
            var printError = function( req, status, err ) {
                alert("f c");
            };

            // Create an object to describe the AJAX request
            var ajaxOptions = {
                url: 'currentarticle.php',
                dataType: 'json',
                success: updatePage,
                error: printError
            };

            // Initiate the request!
            $.ajax(ajaxOptions);

        }


        function jsRecordNext()
        {
            // ... the AJAX request is successful
            var updatePage = function( response ) {
                json_string = JSON.stringify(response);
                jsBlankArticle();
                jsShowArticle();
            };

            // ... the AJAX request fail
            var printError = function( req, status, err ) {
                alert("f n");
            };

            // Create an object to describe the AJAX request
            var ajaxOptions = {
                url: 'nextarticle.php',
                dataType: 'json',
                success: updatePage,
                error: printError
            };

            // Initiate the request!
                $.ajax(ajaxOptions);
        }

        function jsShowArticle()
        {
            js_articles = JSON.parse(json_string);
            document.form_articles.newItem.value=js_articles[1];
            document.form_articles.newItemNo.value=js_articles[2];
            document.form_articles.newMaterial.value=js_articles[3];
            document.form_articles.newAge.value=js_articles[4];
            document.form_articles.newItemSize.value=js_articles[5];
            document.form_articles.newPrice.value=js_articles[6];
            document.form_articles.newInfo.value=js_articles[7];
            document.form_articles.newInfoRed.value=js_articles[8];
            document.form_articles.newArrivalDate.value=js_articles[9];
            if (js_articles[10]="Y")
            {
                document.form_articles.newArrivalDateShown.checked=true;
            }
            else
            {
                document.form_articles.newArrivalDateAhown.checked=false;
            }
            document.form_articles.newMainPicLink.value=js_articles[11];
            document.form_articles.newItemCondition.value=js_articles[12];
        }

        function jsBlankArticle()
        {
            document.form_articles.newItem.value="";
            document.form_articles.newItemNo.value="";
            document.form_articles.newMaterial.value="";
            document.form_articles.newAge.value="";
            document.form_articles.newItemSize.value="";
            document.form_articles.newPrice.value="";
            document.form_articles.newInfo.value="";
            document.form_articles.newInfoRed.value="";
            document.form_articles.newArrivalDate.value="";
            document.form_articles.newArrivalDateShown.checked=false;
            document.form_articles.newMainPicLink.value="";
            document.form_articles.newItemCondition.value="";
        }

        function jsNewArticle()
        {
        jsBlankArticle();
        document.getElementById('formheadline').innerHTML='Article Database - Insert New Item';
        document.getElementById('newItem').focus();
        document.getElementById("recordWrite").disabled = false;
        }


        function jsWriteArticle()
        {
        document.getElementById('formheadline').innerHTML='Article Database - I save the new item';



        document.getElementById("recordWrite").disabled = true;
        }


        function jsResetForm()
        {
        jsBlankArticle();
        document.getElementById('formheadline').innerHTML='Article Database';
        document.getElementById("recordWrite").disabled = true;
        jsRecordCurrent()
        }

        jsResetForm();


        // -->
    </SCRIPT>



</head>

<body class="page page-id-11505 page-template-default" onload="jsRecordCurrent()">

    <div id="page-wrap">s

        <?php
        include('../includes/header.html');
        ?>





        <div id="container-main">
        <div id="main-content">




        <div class="post" id="post-11505">

            <h2 class="title-page">SoB - Administration</h2>

            <title>SoB - Administration</title>

            <div id="recordnumber"></div>

            <div class="entry">

                <form method="post" action="<?=$_SERVER['PHP_SELF']?>" name="form_articles">
                    <table border="0" cellpadding="0" cellspacing="5">

                        <tr>
                            <td align="right">
                            </td>
                            <td align="left">
                                <span id="formheadline"><h2>Article Database</h2></span>
                            </td>
                        </tr>

                        <tr>
                            <td align="right">
                            </td>
                            <td align="left">
                                <span style="padding-right:20px"><font color="orangered" size="+1"><tt><b>*</b></tt></font>indicates a required field</span>
                            </td>
                        </tr>

                        <br>

                        <tr>
                            <td align="right">
                                <span style="padding-right:20px">Item</span>
                            </td>
                            <td>
                                <input id="newItem" name="newItem" type="text" maxlength="100" size="25"/>
                                <font color="orangered" size="+1"><tt><b>*</b></tt></font>
                            </td>
                        </tr>

                        <tr>
                            <td align="right">
                                <span style="padding-right:20px">Item No.</span>
                            </td>
                            <td>
                                <input name="newItemNo" type="text" maxlength="100" size="25" />
                                <font color="orangered" size="+1"><tt><b>*</b></tt></font>
                            </td>
                        </tr>

                        <tr>
                            <td align="right">
                                <span style="padding-right:20px">Arrival Date</span>
                            </td>
                            <td>
                                <input name="newArrivalDate" type="date" />
                                <font color="orangered" size="+1"><tt><b>*</b></tt></font>
                            </td>
                        </tr>

                        <tr>
                            <td align="right">
                                <span style="padding-right:20px">Show in New Arrivals</span>
                            </td>
                            <td>
                                <input name="newArrivalDateShown" type="checkbox" />
                            </td>
                        </tr>

                        <tr>
                            <td align="right">
                                <span style="padding-right:20px">Material</span>
                            </td>
                            <td>
                                <input name="newMaterial" type="text" maxlength="100" size="25" />
                            </td>
                        </tr>

                        <tr>
                            <td align="right">
                                <span style="padding-right:20px">Condition of item</span>
                            </td>
                            <td>
                                <input id="newItemCondition"  name="newItemCondition" type="text" maxlength="100" size="25" />
                            </td>
                        </tr>

                        <tr>
                            <td align="right">
                                <span style="padding-right:20px">Age</span>
                            </td>
                            <td>
                                <input name="newAge" type="text" maxlength="100" size="25" />
                            </td>
                        </tr>

                        <tr>
                            <td align="right">
                                <span style="padding-right:20px">Item Size</span>
                            </td>
                            <td>
                                <input name="newItemSize" type="text" maxlength="100" size="25" />
                            </td>
                        </tr>

                        <tr>
                            <td align="right">
                                <span style="padding-right:20px">Price</span>
                            </td>
                            <td>
                                <input name="newPrice" type="text" maxlength="100" size="25" />
                                <font color="orangered" size="+1"><tt><b>*</b></tt></font>
                            </td>
                        </tr>

                        <tr>
                            <td align="right">
                                <span style="padding-right:20px">Info Red</span>
                            </td>
                            <td>
                                <input name="newInfoRed" type="text" maxlength="100" size="25" />
                            </td>
                        </tr>

                        <tr valign="top">
                            <td align="right">
                                <span style="padding-right:20px">Infos</span>
                            </td>
                            &nbsp;&nbsp;
                            <td>
                                <textarea wrap="soft" name="newInfo" rows="5" cols="30"></textarea>
                            </td>
                        </tr>

                        <tr>
                            <td align="right">
                                <span style="padding-right:20px">PicLink</span>
                            </td>
                            <td>
                                <input id="newMainPicLink" name="newMainPicLink" type="text" maxlength="100" size="50" />
                            </td>
                        </tr>
                        <br><br>

                        <tr>
                            <td align="right" colspan="2">
                                <hr noshade="noshade" />
                                <input type="button" name="recordPrevious" value=" < " onclick="jsRecordPrevious()"/>
                                <input type="button" name="recordNext" value=" > " onclick="jsRecordNext()"/>
                                <input type="button" name="recordNew" value=" New "  onclick="jsBlankArticle()"/>
                                <input type="button" name="recordEdit" value=" Edit " onclick="jsShowArticle()"/>
                                <span style="padding-right:20px"></span>
                                <input type="reset" value="Reset Form" />
                                <input id="recordWrite" type="button" name="recordWrite" value=" Write " onclick="jsWriteArticle()"/>
                            </td>
                        </tr>
                    </table>
                </form>

            </div>

        </div>




</div>

            <?php
            include('../includes/sidemenu.html');
            ?>

            <br class="clearfloat" />
     </div> <!-- End of main container -->

</div><!-- END Page Wrap -->

    <?php
    include('../includes/footer.html');
    ?>

</body>

</html>

Upvotes: 2

Views: 1189

Answers (1)

Pratik Joshi
Pratik Joshi

Reputation: 11693

Hello you lack lots of Logocal and Programming skills, please improve it.

Files() are as below ->

Your index.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US">
<META HTTP-Equiv="FileTransfer" Content="TransferEvent:url('Javascript:alert('%s')'); Transfer">

<head>
    <meta charset="UTF-8"/>
    <title>SoB - Administration</title>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
    <style type="text/css">.recentcomments a {
            display: inline !important;
            padding: 0 !important;
            margin: 0 !important;
        }</style>

    <script id="source" language="javascript" type="text/javascript">
        var js_string;
        document.getElementById("recordWrite").disabled = true;
        function jsRecordPrevious() {
            // ... the AJAX request is successful
            var updatePage = function (response) {
                json_string = JSON.stringify(response);
                jsBlankArticle();
                jsShowArticle();
            };
            // ... the AJAX request fail
            var printError = function (req, status, err) {
                $('#recordnumber').html('-');
                alert("f p");
            };
            // Create an object to describe the AJAX request
            var ajaxOptions = {
                url: 'previousarticle.php',
                data : {  currentRecord: $("[name='recordPrevious']").attr("id")},
                dataType: 'json',
                success: updatePage,
                error: printError
            };
            // Initiate the request!
            $.ajax(ajaxOptions);
        }

        function jsRecordCurrent() {
            // ... the AJAX request is successful
            var updatePage = function (response) {
                json_string = JSON.stringify(response);
                jsBlankArticle();
                jsShowArticle();
            };
            // ... the AJAX request fail
            var printError = function (req, status, err) {
                alert("f c");
            };
            // Create an object to describe the AJAX request
            var ajaxOptions = {
                url: 'currentarticle.php',
                dataType: 'json',
                success: updatePage,
                error: printError
            };
            // Initiate the request!
            $.ajax(ajaxOptions);
        }

        function jsRecordNext() {
            // ... the AJAX request is successful
            var updatePage = function (response) {
                json_string = JSON.stringify(response);
                jsBlankArticle();
                jsShowArticle();
            };
            // ... the AJAX request fail
            var printError = function (req, status, err) {
                alert("f n");
            };
            // Create an object to describe the AJAX request
            var ajaxOptions = {
                url: 'nextarticle.php',
                data : {  currentRecord: $("[name='recordNext']").attr("id")},
                dataType: 'json',
                success: updatePage,
                error: printError
            };
            // Initiate the request!
            $.ajax(ajaxOptions);
        }

        function jsShowArticle() {
            js_articles = JSON.parse(json_string);
            //Dude , I added it (Pratik)->
            $('[name="recordNext"]').attr("id",js_articles[0]);
            $('[name="recordPrevious"]').attr("id",js_articles[0]);

            document.form_articles.newItem.value = js_articles[1];
            document.form_articles.newItemNo.value = js_articles[2];
            document.form_articles.newMaterial.value = js_articles[3];
            document.form_articles.newAge.value = js_articles[4];
            document.form_articles.newItemSize.value = js_articles[5];
            document.form_articles.newPrice.value = js_articles[6];
            document.form_articles.newInfo.value = js_articles[7];
            document.form_articles.newInfoRed.value = js_articles[8];
            document.form_articles.newArrivalDate.value = js_articles[9];
            if (js_articles[10] = "Y") {
                document.form_articles.newArrivalDateShown.checked = true;
            }
            else {
                document.form_articles.newArrivalDateAhown.checked = false;
            }
            document.form_articles.newMainPicLink.value = js_articles[11];
            document.form_articles.newItemCondition.value = js_articles[12];
        }

        function jsBlankArticle() {
            document.form_articles.newItem.value = "";
            document.form_articles.newItemNo.value = "";
            document.form_articles.newMaterial.value = "";
            document.form_articles.newAge.value = "";
            document.form_articles.newItemSize.value = "";
            document.form_articles.newPrice.value = "";
            document.form_articles.newInfo.value = "";
            document.form_articles.newInfoRed.value = "";
            document.form_articles.newArrivalDate.value = "";
            document.form_articles.newArrivalDateShown.checked = false;
            document.form_articles.newMainPicLink.value = "";
            document.form_articles.newItemCondition.value = "";
        }

        function jsNewArticle() {
            jsBlankArticle();
            document.getElementById('formheadline').innerHTML = 'Article Database - Insert New Item';
            document.getElementById('newItem').focus();
            document.getElementById("recordWrite").disabled = false;
        }


        function jsWriteArticle() {
            document.getElementById('formheadline').innerHTML = 'Article Database - I save the new item';


            document.getElementById("recordWrite").disabled = true;
        }

        function jsResetForm() {
            jsBlankArticle();
            document.getElementById('formheadline').innerHTML = 'Article Database';
            document.getElementById("recordWrite").disabled = true;
            jsRecordCurrent()
        }
        jsResetForm();
    </script>
</head>

<body class="page page-id-11505 page-template-default" onload="jsRecordCurrent()">

<div id="page-wrap">
    <div id="container-main">
        <div id="main-content">
            <div class="post" id="post-11505">
                <h2 class="title-page">SoB - Administration</h2>
                <title>SoB - Administration</title>
                <div id="recordnumber"></div>
                <div class="entry">
                    <form method="post" action="<?= $_SERVER['PHP_SELF'] ?>" name="form_articles">
                        <table border="0" cellpadding="0" cellspacing="5">
                            <tr>
                                <td align="right">
                                </td>
                                <td align="left">
                                    <span id="formheadline"><h2>Article Database</h2></span>
                                </td>
                            </tr>

                            <tr>
                                <td align="right">
                                </td>
                                <td align="left">
                                    <span style="padding-right:20px"><font color="orangered" size="+1"><tt><b>*</b></tt></font>indicates a required field</span>
                                </td>
                            </tr>

                            <tr>
                                <td align="right">
                                    <span style="padding-right:20px">Item</span>
                                </td>
                                <td>
                                    <input id="newItem" name="newItem" type="text" maxlength="100" size="25"/>
                                    <font color="orangered" size="+1"><tt><b>*</b></tt></font>
                                </td>
                            </tr>

                            <tr>
                                <td align="right">
                                    <span style="padding-right:20px">Item No.</span>
                                </td>
                                <td>
                                    <input name="newItemNo" type="text" maxlength="100" size="25"/>
                                    <font color="orangered" size="+1"><tt><b>*</b></tt></font>
                                </td>
                            </tr>

                            <tr>
                                <td align="right">
                                    <span style="padding-right:20px">Arrival Date</span>
                                </td>
                                <td>
                                    <input name="newArrivalDate" type="date"/>
                                    <font color="orangered" size="+1"><tt><b>*</b></tt></font>
                                </td>
                            </tr>

                            <tr>
                                <td align="right">
                                    <span style="padding-right:20px">Show in New Arrivals</span>
                                </td>
                                <td>
                                    <input name="newArrivalDateShown" type="checkbox"/>
                                </td>
                            </tr>

                            <tr>
                                <td align="right">
                                    <span style="padding-right:20px">Material</span>
                                </td>
                                <td>
                                    <input name="newMaterial" type="text" maxlength="100" size="25"/>
                                </td>
                            </tr>

                            <tr>
                                <td align="right">
                                    <span style="padding-right:20px">Condition of item</span>
                                </td>
                                <td>
                                    <input id="newItemCondition" name="newItemCondition" type="text" maxlength="100"
                                           size="25"/>
                                </td>
                            </tr>

                            <tr>
                                <td align="right">
                                    <span style="padding-right:20px">Age</span>
                                </td>
                                <td>
                                    <input name="newAge" type="text" maxlength="100" size="25"/>
                                </td>
                            </tr>

                            <tr>
                                <td align="right">
                                    <span style="padding-right:20px">Item Size</span>
                                </td>
                                <td>
                                    <input name="newItemSize" type="text" maxlength="100" size="25"/>
                                </td>
                            </tr>

                            <tr>
                                <td align="right">
                                    <span style="padding-right:20px">Price</span>
                                </td>
                                <td>
                                    <input name="newPrice" type="text" maxlength="100" size="25"/>
                                    <font color="orangered" size="+1"><tt><b>*</b></tt></font>
                                </td>
                            </tr>

                            <tr>
                                <td align="right">
                                    <span style="padding-right:20px">Info Red</span>
                                </td>
                                <td>
                                    <input name="newInfoRed" type="text" maxlength="100" size="25"/>
                                </td>
                            </tr>

                            <tr valign="top">
                                <td align="right">
                                    <span style="padding-right:20px">Infos</span>
                                </td>
                                &nbsp;&nbsp;
                                <td>
                                    <textarea wrap="soft" name="newInfo" rows="5" cols="30"></textarea>
                                </td>
                            </tr>

                            <tr>
                                <td align="right">
                                    <span style="padding-right:20px">PicLink</span>
                                </td>
                                <td>
                                    <input id="newMainPicLink" name="newMainPicLink" type="text" maxlength="100"
                                           size="50"/>
                                </td>
                            </tr>
                            <br><br>

                            <tr>
                                <td align="right" colspan="2">
                                    <hr noshade="noshade"/>
                                    <input type="button" name="recordPrevious" value=" < "
                                           onclick="jsRecordPrevious()"/>
                                    <input type="button" name="recordNext" value=" > " onclick="jsRecordNext()"/>
                                    <input type="button" name="recordNew" value=" New " onclick="jsBlankArticle()"/>
                                    <input type="button" name="recordEdit" value=" Edit " onclick="jsShowArticle()"/>
                                    <span style="padding-right:20px"></span>
                                    <input type="reset" value="Reset Form"/>
                                    <input id="recordWrite" type="button" name="recordWrite" value=" Write "
                                           onclick="jsWriteArticle()"/>
                                </td>
                            </tr>
                        </table>
                    </form>
                </div>
            </div>
        </div>
        <br class="clearfloat"/>
    </div>
    <!-- End of main container -->
</div>
<!-- END Page Wrap -->
</body>
</html>

This is currentarticle.php

<?php
$link = mysql_connect('localhost', 'root', '');
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db('testDb', $link);
if (!$db_selected) {
    die ('Can\'t use foo : ' . mysql_error());
}

$result = mysql_query("SELECT * FROM articles ORDER BY id ASC LIMIT 1");
$result = mysql_fetch_row($result);
echo json_encode($result);
?>

This is previousarticle.php

<?php
$link = mysql_connect('localhost', 'root', '');
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db('testDb', $link);
if (!$db_selected) {
    die ('Can\'t use foo : ' . mysql_error());
}
$current_id = $_REQUEST['currentRecord'];

$result = mysql_query("SELECT * FROM articles WHERE id < ".$current_id." ORDER BY id ASC LIMIT 1");
$result = mysql_fetch_row($result);
echo json_encode($result);
?>

This is nextarticle.php

<?php
$link = mysql_connect('localhost', 'root', '');
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db('testDb', $link);
if (!$db_selected) {
    die ('Can\'t use foo : ' . mysql_error());
}
$current_id = $_REQUEST['currentRecord'];
$result = mysql_query("SELECT * FROM articles WHERE id > ".$current_id." ORDER BY id ASC LIMIT 1");
$result = mysql_fetch_row($result);
echo json_encode($result);
?>

I made changes in all files in some extent.So please modify accordingly in your code.And do proper coding from next time.

And you add validation like If its last row , disable NEXT button , if its 1st row , disable PREV button.I solved what you asked.

Thanks!

Upvotes: 1

Related Questions