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

Related Questions

I have one table structure Like 1)Id 2)Date 3)score Filtered by date, I can
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 the following table structure CREATE TABLE `table` ( `id` int(11) NOT NULL
I have a table with a structure like the following: LocationID AccountNumber long-guid-here 12345
This is the MySQL table structure that I have: itemID (BIGINT) userID (BIGINT) wasAdded
I have a couple of mdb files with the exact table structure. I have
I have already googled for this I have a Table with following structure in
I have a few classes, such as those that outline database table structure or
I have a table in my database which stores a tree structure. Here are

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.