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

  • Home
  • SEARCH
  • 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 771935
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T18:43:57+00:00 2026-05-14T18:43:57+00:00

I have a Table structure as id, trackid, table_name, operation, oldvalue, newvalue, field, changedonetime

  • 0

I have a Table structure as
id, trackid, table_name, operation, oldvalue, newvalue, field, changedonetime

Now if I have 3 rows for the same “trackid” same “field”, then how can i select the latest out of the three?

i.e. for e.g.:

id = 100 trackid = 152 table_name
= jos_menu operation= UPDATE oldvalue = IPL newvalue = IPLcccc
field = name live = 0 changedonetime =
2010-04-30 17:54:39

and

id = 101 trackid = 152 table_name =
jos_menu operation= UPDATE oldvalue
= IPLcccc newvalue = IPL2222 field = name live = 0 changedonetime =
2010-04-30 18:54:39

As u can see above the secind entry is the latest change,
Now what query I shoud use to get the only one and Latest row out of many such rows…

UPDATED

$distupdqry = "select DISTINCT trackid,table_name from jos_audittrail where live = 0 AND operation = 'UPDATE'";
$disupdsel = mysql_query($distupdqry);
$t_ids = array();
$t_table = array();
while($row3 = mysql_fetch_array($disupdsel))
{   
    $t_ids[] = $row3['trackid'];
    $t_table[] = $row3['table_name'];
    //$t_table[] = $row3['table_name'];
}

//echo "<pre>";print_r($t_table);echo "<pre>";

//exit;
for($n=0;$n<count($t_ids);$n++)
{

      $qupd = "SELECT * FROM jos_audittrail WHERE operation = 'UPDATE'  AND trackid=$t_ids[$n] order by changedone DESC ";
    $seletupdaudit = mysql_query($qupd);
    $row4 = array();
    $audit3 = array();
    while($row4 = mysql_fetch_array($seletupdaudit))
    {   
        $audit3[] = $row4;  
    }           


        $updatefield = '';
        for($j=0;$j<count($audit3);$j++)
        {
            if($j == 0)
            {

                if($audit3[$j]['operation'] == "UPDATE")
                {
                            //$insqry .= $audit2[$i]['operation']." ";
                            //echo "<br>";
                    $updatefield .= "UPDATE `".$audit3[$j]['table_name']."` SET ";

                }
            }

            if($audit3[$j]['operation'] == "UPDATE")
            {

                $updatefield .= $audit3[$j]['field']." = '".$audit3[$j]['newvalue']."', ";

            }

        }
        /*echo "<pre>";
    print_r($audit3);
    exit;*/
        $primarykey = "SHOW INDEXES FROM `".$t_table[$n]."` WHERE Key_name = 'PRIMARY'";
        $prime = mysql_query($primarykey);
        $pkey = mysql_fetch_array($prime);
        $updatefield .= "]";
        echo $updatefield = str_replace(", ]"," WHERE ".$pkey['Column_name']." = '".$t_ids[$n]."'",$updatefield);   
}

Here I am creating the Update query by fetching the records from the initially described table which is here mentioned as audittrail table… please go throught the code.. and see how can i make the required change i need finally..

  • 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-14T18:43:57+00:00Added an answer on May 14, 2026 at 6:43 pm
    select * from TableName order by id DESC LIMIT 1
    

    EDITED. YEs you can if you want to order by “changedonetime” USE.

    select * from TableName order by changedonetime DESC LIMIT 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 532k
  • Answers 531k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer It turns out that there's a handle to that file… May 17, 2026 at 12:02 am
  • Editorial Team
    Editorial Team added an answer You could change the image using canvas. There are dozens… May 17, 2026 at 12:02 am
  • Editorial Team
    Editorial Team added an answer Update: Changed my example to match your updated question Here's… May 17, 2026 at 12:02 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have one table structure Like 1)Id 2)Date 3)score Filtered by date, I can
I have table structure like this: ID cond 1 5 1 2 1 6
i have table structure with 3 colums (column1, column2, column3) and i want to
I have a table structure that looks like: <table> <tr id=row1> <td> <div>row 1
I have following table structure: Table: Plant PlantID: Primary Key PlantName: String Table: Party
I have this table structure: - CategoryID - CategoryName - ParentID I want to
I have following table structure in my DB ID Name -------------------------- ID_1 Name1 ID1
I am using MySQL 5.0. I have table with following structure and data. CREATE
I have a table structure: <tr> <td> <a href=# class=xx></a> </td> <td> data </td>
I have following table structure. <table> <tr> <td><a href=#></td> </tr> </table> When I click

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.