Welcome Guest, Not a member yet? Register   Sign In
Gathering data BASED on already gathered data?
#4

[eluser]kgill[/eluser]
What you want is a join, join your todo_lists table to the todo_entries table using the list id. If it's possible to have an entry in todo_lists without an entry in todo_entries then you want a left outer join instead. This will return data like so:
Code:
list1   entry1
list1   entry2
list1   entry3
list2   entry1
list3   entry1
list3   entry2

The fact that you get repeating values in the first column makes people think this is somehow wrong but that's exactly what you want. You just need to alter your logic a bit to deal with them.

Code:
// instead of
foreach ($foo as $bar) {
  echo $bar['list_item'];
  echo $bar['list_entry'];
}

// you need
$curr_item = null;
foreach ($foo as $bar) {
  if ($bar['list_item'] <> $curr_item) {
    echo $bar['list_item'];
    echo $bar['list_entry'];
    $curr_item = $bar['list_item'];
  } else {
    echo $bar['list_entry'];
  }
}
So basically each time the value in list_item changes you print the list item otherwise you just print the entry - hope that makes sense.

- K


Messages In This Thread
Gathering data BASED on already gathered data? - by El Forum - 06-18-2009, 10:26 PM
Gathering data BASED on already gathered data? - by El Forum - 06-18-2009, 10:46 PM
Gathering data BASED on already gathered data? - by El Forum - 06-18-2009, 10:50 PM
Gathering data BASED on already gathered data? - by El Forum - 06-18-2009, 10:55 PM
Gathering data BASED on already gathered data? - by El Forum - 06-18-2009, 11:06 PM
Gathering data BASED on already gathered data? - by El Forum - 06-18-2009, 11:37 PM



Theme © iAndrew 2016 - Forum software by © MyBB