Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Aug 2006
    Location
    Richmond, CA
    Posts
    210
    Thanks
    3
    Thanked 11 Times in 10 Posts

    Question on merging multi-dimensional arrays

    I have 2 arrays. They both represent data returned from a database query. Each array item is an array (row of data in the database).

    What I'd like to do is to merge the arrays, but to remove duplicate IDs (which is not the array index...)

    I know.... Why?

    I'm keeping a calendar. I want to list the next X items in the calendar. The first array is a list of recurring events (every Tuesday, every 15th of the month, etc...) and the second list is the one-time events. The catch is that a one-time event can over-ride an instance of a recurring event. (For example, if I have a class every Tuesday night, I set that as a recurring event. I can then enter a one time event (say, going to my niece's play) and when I list the events, the play comes up instead of the class for that evening...)

    Right now, what I'm doing is going through the array items one by one and checking the values, then replacing them. Is there an easier way to do this?

    Thanks.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    This sounds like a job for SQL.
    I assume its coming from the same table yeah? How do you determine recurrance, just with the use of a flag / field for it?
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,576
    Thanks
    80
    Thanked 4,497 Times in 4,461 Posts
    Assuming all these events are in the same table, I certainly would tend to agree with FouLu.

    But without seeing you DB schema, we can't be sure. I think it depends a lot on how you define recurring events in the DB.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #4
    Regular Coder
    Join Date
    Aug 2006
    Location
    Richmond, CA
    Posts
    210
    Thanks
    3
    Thanked 11 Times in 10 Posts
    They're not coming from the same table, but it's sounding more and more like that's the way to go. Since I'd have to redo the schema anyways, any suggestions on how to set it up (in particular, what would I need to do to have a query do that work?)

    Thanks.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •