On Thursday 30 May 2002 11:30, Steve G wrote:

Please do not reply to an existing post. Start a new one!

> I do not understand why PHP is trying to pull row 2!!  I want to create an
> array of data and construct a table from a query.  The echo of $rows shows
> 2 rows, so if I'm setting my variable to 0 and incrementing with each loop,
> it doesn't make sense to me why it tries to pull row 2.  It should stop at
> row 1 because the next loop would make the variable 2 and the if says if
> $ii is less than 2.

The if statement only runs once. At the time it is run the statement is true 
(ie $ii < 2) ...

> WHAT AM I MISSING!?
>
> I have a while loop written to pull data from a postgreSQL database.  I
> have 2 and only 2 rows of data in this table.  Probably labeled within
> PostgreSQL as '0' and '1'.  The browser displays the error message along
> with the proper table listed below it!!

... but inside your while loop you have $ii++, which results in ...

>   Warning: Unable to jump to row 2 on PostgreSQL result index 2 in
> /var/www/html/steve/frontdoor.php on line 92
>    sgaas  Steve  Gaas
>       mjohnson  Matt  Johnson

Basically you're going about this the wrong way. Replace this:

> <?
> if ( $ii < $rows) {
>  while ($tabledata = pg_fetch_array($results, $ii)) {    <--(LINE 92)
>
>  $username = $tabledata["username"];
>  $firstname = $tabledata["firstname"];
>  $lastname = $tabledata["lastname"];
>  echo "<TR>\n";
>  echo "<td>$username</td>\n";
>  echo "<td>$firstname</td>\n";
>  echo "<td>$lastname</td>\n";
>  echo "</tr>\n";
>  $ii++;
>  }
>
>   }
> ?>

with:

  /** Untested use with extreme caution **/
  while ($tabledata = pg_fetch_array($results)) {
    $username = $tabledata["username"];
    $firstname = $tabledata["firstname"];
    $lastname = $tabledata["lastname"];
    echo "<TR>\n";
    echo "<td>$username</td>\n";
    echo "<td>$firstname</td>\n";
    echo "<td>$lastname</td>\n";
    echo "</tr>\n";
  }

-- 
Jason Wong -> Gremlins Associates -> www.gremlins.com.hk
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *

/*
Occam's eraser:
        The philosophical principle that even the simplest
        solution is bound to have something wrong with it.
*/


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to