tags:

views:

55

answers:

2

EDITED

I m using this select query with left join:

$updaterbk = "SELECT j1. *
FROM jos_audittrail j1
LEFT OUTER JOIN jos_audittrail j2 ON ( j1.trackid != j2.trackid
AND j1.field != j2.field
AND j1.changedone < j2.changedone )
WHERE j1.operation = 'UPDATE'
AND j2.id IS NULL
";

which outputs me an array:

Array
(
    [0] => Array
        (
            [id] => 137
            [trackid] => 153
            [table_name] => jos_menu
            [operation] => UPDATE
            [oldvalue] => 0
            [newvalue] => 62
            [field] => checked_out
            [live] => 0
            [changedone] => 2010-05-11 17:46:28
        )
    [1] => Array
        (
            [id] => 138
            [trackid] => 153
            [table_name] => jos_menu
            [operation] => UPDATE
            [oldvalue] => 0000-00-00 00:00:00
            [newvalue] => 2010-05-11 12:16:28
            [field] => checked_out_time
            [live] => 0
            [changedone] => 2010-05-11 17:46:28
        )
    [2] => Array
        (
            [id] => 139
            [trackid] => 153
            [table_name] => jos_menu
            [operation] => UPDATE
            [oldvalue] => Subhash
            [newvalue] => Subhashgfhfgh
            [field] => name
            [live] => 0
            [changedone] => 2010-05-11 17:46:35
        )
    [3] => Array
        (
            [id] => 140
            [trackid] => 153
            [table_name] => jos_menu
            [operation] => UPDATE
            [oldvalue] => subhash
            [newvalue] => subhashhfhf
            [field] => alias
            [live] => 0
            [changedone] => 2010-05-11 17:46:35
        )
    [4] => Array
        (
            [id] => 141
            [trackid] => 153
            [table_name] => jos_menu
            [operation] => UPDATE
            [oldvalue] => 62
            [newvalue] => 0
            [field] => checked_out
            [live] => 0
            [changedone] => 2010-05-11 17:46:35
        )
    [5] => Array
        (
            [id] => 142
            [trackid] => 153
            [table_name] => jos_menu
            [operation] => UPDATE
            [oldvalue] => 2010-05-11 12:16:28
            [newvalue] => 0000-00-00 00:00:00
            [field] => checked_out_time
            [live] => 0
            [changedone] => 2010-05-11 17:46:35
        )
)

here in this array I dont want any values to be displayed twice for, i.e. I ned the first occurrence of the value only. Now here u can see that the index "field" has repeated values i.e. "checked_out" and "checked_out_time" other indexes have single occurrence, now what should I do to select/grab the first occurrence of the repetitive values only?

+2  A: 

this appears to be the result of a database query, so i would suggest to change the query to only select unique field values.

<UPDATE> for getting unique field values, you can try grouping on that column:

SELECT j1.*
FROM jos_audittrail j1
  LEFT OUTER JOIN jos_audittrail j2 ON (
    j1.trackid != j2.trackid
    AND j1.field != j2.field
    AND j1.changedone < j2.changedone
  )
WHERE j1.operation = 'UPDATE'
  AND j2.id IS NULL
GROUP BY j1.field

you might have to add all other SELECTed columns to the GROUP BY, ie. GROUP BY j1.field, j1.id, j1.trackid, ....</UPDATE>

it would help if you could give some more context: what system are you using, what are you trying to achieve, the expected output, the database query being executed, etc. and: please remove the integer keys and their values ([6] => checked_out_time) from your debug output, because the don't add any information ([field] => checked_out_time is the same, but with a more meaningful key).

ax
Pls chk the updated question
OM The Eternity
please check the updated answer :)
ax
+1  A: 

What sort of output are you expecting? Can you provide a code example with what you're trying to accomplish?

The only thing I can give you with the provided information is that you should use the function:

foreach($thatArray as $index => $subArray)
 if(($key = array_search('checked_out', $subArray))!==false)
  return $key;

That's what I think you want.

Daniel
Pls chk the updated question
OM The Eternity