php...@jakeman.plus.com wrote:
> Hi kaaposc,
> 
[snip]
> 
> Yes, it did help. No changes needed to the HTML, but the PHP now works using
> mysqli_fetch_array() and array_push():
> 
> <?php
> $dbc = mysqli_connect("localhost", "root", "cae001", "cjfiles"); 
> $query_resource = mysqli_query($dbc, "SELECT * FROM article");
> $records = mysqli_num_rows($query_resource);
> 
> $items = array();
> while ($row = mysqli_fetch_array($query_resource, MYSQL_BOTH)) {
>   array_push($items, $row);
> }
> 
[snip]

Another option would be to write a simple Iterator wrapper around the
query resource so the results are fetched "live" by PHPTAL.  This is
especially useful if you have a LARGE result set and don't want to
expend the memory on storing the entire result set in an array.

(Note that this is designed to wrap around the PEAR DB layer, but you
can quickly replace those pieces with the mysqli equivalent)

class DBResultIterator implements Iterator {
    private $current;
    private $res;
    private $rowindex;

    function __construct(DB_Result $res)
    {
        $this->res = $res;
        $rowindex = -1;
        $this->current = null;
    }

    function current()
    {
        return $this->current;
    }

    function next()
    {
        $this->current =& $this->res->fetchRow();
        $this->rowindex++;
        return $this->current;
    }

    function key()
    {
        return $this->rowindex;
    }

    function rewind()
    {
        $this->rowindex++;
        $this->current =& $this->res->fetchRow();
        return false;
    }

    function valid()
    {
        return $this->current ? true : false;
    }
}


_______________________________________________
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal

Reply via email to