SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    May 2006
    Posts
    89
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Push versus Pull

    I'd like to know if there's alot of difference (performance wise) between:

    - executing a query, looping the result rows & adding them to an array, then assigning them to the template, then looping through them once more to display.

    - executing a query, assigning result to template, then looping over result set (mysql_fetch_assoc()) to display each row.

    Also, second method: Will there be an accumulation of memory if I assign like 5 different result resources before I begin looping over them? ($result = mysql_query(..); assign to template)

    Thanks

  2. #2
    SitePoint Enthusiast Gods Lonely Man's Avatar
    Join Date
    Sep 2006
    Location
    Yes
    Posts
    55
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    - executing a query, assigning result to template, then looping over result set (mysql_fetch_assoc()) to display each row.
    I think this is faster because of the extra loop. Other than that they are the same?

    Every variable in a script comsumses memory, until you "free" them. So yeah, there will be an accumulation of memory if you have 5 different result resources.
    I have no capslock and I must scream....

  3. #3
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by wiskers
    - executing a query, looping the result rows & adding them to an array, then assigning them to the template, then looping through them once more to display.

    - executing a query, assigning result to template, then looping over result set (mysql_fetch_assoc()) to display each row.
    #1 will load the entire result into php's memory, whereas #2 will load on demand. For large resultsets, this can have quite some impact on memory-use. The processing overhead of the extra loop is quite negligible in comparison.

    From a design perspective, I wouldn't want to use mysql_* functions from within a template - You could get around this by using a wrapper for the resultsets. If you're using PHP5, you could let the wrapper implement Iterator, which will let you treat it like it was an array (use foreach)


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
  •