I am stumped by this one. I have tried several angles and some come close but none are completely correct.
I need to select from 3 fields of a table. The first is a log_id with a unique number for each row, the second is an entry_id which originates from another table and has multiples of the same entry numbers and the last is a single letter representing a type.
‘D’ means the corresponding entry has been deleted, BTW.
Example:
"SELECT log_id, entry_id, type from entry_log order by entry_id";
…has the following example outcome (a snip of the real query):
6 1 C
31 1 D
8 2 C
25 2 D
11 3 C
14 3 D
13 3 D
18 4 D
17 4 D
12 4 C
22 5 D
15 5 C
398 6 U
249 6 U
44 6 U
587 6 R
272 6 U
498 6 R
578 6 U
590 6 U
529 6 R
564 6 D
43 7 U
42 7 D
16 7 C
I need to choose the highest row[0] value of each row[1] value whose row[2] value equals ‘D’. In other words, the correct choice when row[1] = 6 is where row[0] = 564 in the array above. I need to put a single entry_id(row[1]) with it’s corresponding log_id(row[0]) into another array.
I have tried the following:
"SELECT MAX(log_id), entry_id, type from entry_log where type = 'D'";
This does not account for the fact that some of row1 have entries higher than ones that match D (as they are no longer deleted).
I’ve tried going backward:
"SELECT log_id, entry_id, type from entry_log where log_id in ('U','R','C','x')";
Again not logical.
$log = "SELECT log_id, entry_id, type from entry_log order by entry_id;
$lgcomp = mysql_query($log);
while ($row = mysql_fetch_array($logcomp, MYSQL_NUM)) {
$cli = $row[0];
$cei = $row[1];
$ct = $row[2];
}
foreach ($cli as $key=>$clid)
if $cei =
…stumped…
foreach($cli as $key => $clid){
$lgentry = $cei[$key];
switch($clid) {
case $lgentry = :
break;
… can’t figure …
I just don’t have the technical understanding of PHP mysql syntax to get this to come out correctly.
Any and all ideas or just pointing me in the right direction will be appreciated. No, you don’t need to write my script (I do like figuring it out which is what this is all about for me) but I have been hashing out a lot of time on this one and I know I am simply missing some syntax and understanding of sorting in PHP/mysql. As far as Internet searching, I only come up with never ending repeats that don’t help in this case.
Thanks! This 72 year old has learned a lot here in the last couple of weeks.
Try this:
Result: