SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Member
    Join Date
    Jan 2002
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Can I query a result set?

    Well, I have my query returning the expected result set to fill out events in a calendar. The query returns all events that begin in that month. I need to pull the events for each day as I write that calendar day block. (The calendar will look like a regular paper wall calendar). I suppose I could query the db for each day, but I don't like the ide of running some 30 odd queries for each page view!

    Is there a way to present the events in each day blaock without the sql overhead?

    Irvin.

  2. #2
    Tranceoholic lilleman's Avatar
    Join Date
    Feb 2004
    Location
    Írebro, Sweden
    Posts
    2,716
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Which scripting/programming language are you using?
    ERIK RIKLUND :: Yes, I've been gone quite a while.

  3. #3
    SitePoint Member
    Join Date
    Jan 2002
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP
    Thanks

  4. #4
    Tranceoholic lilleman's Avatar
    Join Date
    Feb 2004
    Location
    Írebro, Sweden
    Posts
    2,716
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    One solution would be to fetch the events from the database, and then place them in an array grouped by the date.

    PHP Code:
    // I assume that $result is a valid result

    while($event mysql_fetch_assoc($result))
    {
      
    $events[$event['date_field']][] = $event;

    When you're printing the calendar, use this to check if there are any events for that date:

    PHP Code:
    if( isset($events[$currentDate]) )
    {
      foreach( 
    $events[$currentDate] as $event )
      {
        
    // display the event in the calendar
      
    }

    ... where $currentDate holds the current date, with the same format as the dates from the database.
    ERIK RIKLUND :: Yes, I've been gone quite a while.

  5. #5
    SitePoint Member
    Join Date
    Jan 2002
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for your reply Erik.

    Your solution looks promising, but I am at a loss how to impliment it!

    Are all fields in each row of the result set assigned to a field position in the array?

    I want to be able to display an event title, and using the event id create a link to display a popup with event details.

    So, assuming eID is the first, eTitle is the second and eDate is the third element in the query, to print the event title would I do something like:
    Code:
    echo "<br>$event[1]<br>";
    ?

  6. #6
    Tranceoholic lilleman's Avatar
    Join Date
    Feb 2004
    Location
    Írebro, Sweden
    Posts
    2,716
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by iamoraal
    So, assuming eID is the first, eTitle is the second and eDate is the third element in the query, to print the event title would I do something like:
    Code:
    echo "<br>$event[1]<br>";
    ?
    Since we're using mysql_fetch_assoc, you simply use $entry['fieldname'] to access the value:

    PHP Code:
    echo "<br>$event[eTitle]<br>"
    Last edited by lilleman; Feb 4, 2006 at 17:55. Reason: Fixed a typo.
    ERIK RIKLUND :: Yes, I've been gone quite a while.

  7. #7
    SitePoint Member
    Join Date
    Jan 2002
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks,
    I'll work on what you gave me later this evening. If I have any problems, I'll post them tommorow.
    Irvin.

  8. #8
    SitePoint Member
    Join Date
    Jan 2002
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Erik,
    I got it to work. Thanks again for your help!
    Irvin.

  9. #9
    Tranceoholic lilleman's Avatar
    Join Date
    Feb 2004
    Location
    Írebro, Sweden
    Posts
    2,716
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You're welcome. Let me know if there's anything else I can help you with.
    ERIK RIKLUND :: Yes, I've been gone quite a while.


Bookmarks

Posting Permissions

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