Re: [PHP-DB] PHP Objects and SQL Results

[email protected] (Moritz Fuchs)
Newsgroups php.db
Message-ID <[email protected]>
Hi,

Why don't you just try the following:

$query = "SELECT * FROM foo WHERE UserID = " .$uID . " ORDER BY bar";
$result = mysql_query($query);

//get the first row
$row = mysql_fetch_object($result);

//get the next row
while ($next = mysql_fetch_object($result)) {
   //do something with row/next

    //The next row is the current row in the next iteration
    $row = $next;
}

mysql_free_result($result);


Regards
Moritz

On Fri, Feb 12, 2010 at 8:26 PM, Paul <[email protected]> wrote:

> Hi all,
>
> I'm currently having a problem correctly formatting a table within a while
> loop.  I'm using an object to store the results of a query, and using the
> while to iterate through it each row to produce the output:
>
> $query = "SELECT * FROM foo WHERE UserID = " .$uID . " ORDER BY bar";
> $result = mysql_query($query);
>
> while($obj = mysql_fetch_object($result))
> {
>        $obj->bar;
> }
>
> To properly format the table, I need to check the value of bar in the next
> iteration of the object (but have to do it on the current one). Using an
> array, I would do:
>
> next($obj);
> if($obj["bar"] == "something")
> {
>        //do things
> }
> prev($obj);
>
> Is there an equivalent to object?  I've tried the above method, but nothing
> happens.  I've also tried type casting it to an array, without success.
>
> Is there anyway to iterate through this?
>
> Thanks,
> Paul
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.