Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 746471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T14:05:41+00:00 2026-05-14T14:05:41+00:00

How to get the next row from the Database table? Such that the row

  • 0

How to get the next row from the Database table? Such that the row might be incremented row that is if structure has a field called “id” then the row can be id++ or very next incremented row, but it may also b any other id containing row (NOT VERY NEXT) , (because the ids could be deleted from the table).

I am using Mysql Database
below is my code..

mysql_select_db('pranav_test');
$seletaudit = mysql_query("SELECT * FROM jos_audittrail WHERE live = 0");
while($row2 = mysql_fetch_array($seletaudit))
{
    $audit[] =$row2;
}
$trackid = array();
$tracktable = array();
$i = 0;
foreach($audit as $val)
{
    $trackid[$i] = $val['trackid'];
    $tracktable[$i] = $val['table_name'];   

    if($i!=0)
    {
        $prev_id = $trackid[$i-1];
        $prev_valtab = $tracktable[$i-1];
    }
    if($val['operation'] == 'INSERT')
    {
        if($tracktable[$i]!=$prev_valtab)
        {
            $inserttable = "INSERT INTO '".$tracktable[$i]."' (";
        }


        if($tracktable[$i]==$prev_valtab)
        {
            $insertfield .= "'".$val['field']."', ";
        }
        if($tracktable[$i]==$prev_valtab)
        {
            $insertfield .= "]";
            $insertfield = str_replace(", ]",")",$insertfield);

        }
    }
}

here above I need t know whats going to be my next rows’s “table_name” field contain…
how can i do that….?
Please help for fetching the next row in the for loop to get it checked.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T14:05:42+00:00Added an answer on May 14, 2026 at 2:05 pm

    UPDATE:

    Ok, now that you posted some code, here a more specific answer:

    If you want to have access to the next row in the array, I suggest to use a normal for loop to have access to the index:

    for($i = 0; $i<count($audit); $i++) {
         // $audit[$i] is current row
         // $audit[$i+1] is next row
    }
    

    But be careful when you reach the end of the array, as $i+1 will be out of bounds.

    Or if you just wonder why the $i in your current code is not behaving correctly:
    You have to increment it at the end of your foreach loop:

    $i++;
    

    UPDATE2:
    A more complete example to make it clear (I adapt your approach and check for the previous row)

    for($i=0; $i<count($audit);$i++)
    {
        $curr = $audit[$i];
    
        if($i>0) {
            $prev = $audit[$i-1];
    
            if($curr['operation'] == 'INSERT')
            {
                if($curr['table_name']!=$prev['table_name'])
                {
                    $inserttable = "INSERT INTO '".$curr['table_name]."' (";
                }
                else {
                    // whereever $insertfield comes from
                    $insertfield .= "'".$curr['field']."', ";
                    $insertfield .= "]";
                    $insertfield = str_replace(", ]",")",$insertfield);
    
                }
            }
        }
    }
    

    As you have not specified at all how you connect to the database, here is a generic answer:

    Specify your query to order the result set by ID:

    $query = "SELECT <columns here> FROM <table here> ORDER BY id";
    

    Then get the result set (we have a fictive database class):

    $result = $db->query($query);
    

    Then iterate over the resultset:

    while($row = $result->next()) {
        // do something with row
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using the next instructions to get some registers from my Database. Create
I want to increment $x in this function to get next record in table.
I was looking for an anwer to question Get next N elements from enumerable
How do you get the graphic that is next to the address bar show
I have a php page that pulls data from a mysql database based on
I have a database that logs when an employee has attended a course and
I'm trying to get all products from the database with a single query. I
I query my mySql database table and retrieve text strings that look like this:
I have a table that has column names similar to ADDRESS, OLD_ADDRESS, CITY, OLD_CITY,
I have a database with a table called shuffledQuestions with 2 columns category_id and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.