SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict MarekS's Avatar
    Join Date
    Jan 2003
    Location
    Estonia / Tallinn
    Posts
    201
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    fetch rows in template file?

    Currently I bulid the array of $items in my external PHP file - smth like this:

    PHP Code:
    //...
    $result mysql_query($SQL);

    $items = array();

    for (
    $i=0$row=mysql_fetch_row($result); $i++) {
        
    $items[$offset++] = array($row[0], $row[1], $row[2], $row[3], $row[4]);
    }

    mysql_close($conn); 
    And then at some stage I include some template file that basically contains HTML plus some simple PHP code to iterate the $items array.

    While it works - I am a little bit concerned (wonder), if this is a good approach? I mean - what if I put the fetch_row in the template side and close the connection as almost the last thing (since there will a little code execured after the template is included).

    I have not tested this solution yet, but one thing I'd get rid like this should basically be the $items array (no need for it anymore). Some free memory - often valuable.

    Any thoughts on this one?

    Thank U,

    - MarekS -

  2. #2
    SitePoint Zealot
    Join Date
    Mar 2002
    Location
    Perth, Australia
    Posts
    164
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have not tested this solution yet, but one thing I'd get rid like this should basically be the $items array (no need for it anymore). Some free memory - often valuable.
    You could unset array $items when you're done with it:
    PHP Code:
    unset($items); 
    http://www.php.net/unset


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
  •