[svlug] PHP database code not...

Michael Robinson plug_1 at robinson-west.com
Wed Nov 12 20:51:02 PST 2014


working as expected.

postgres=# select * from computers where computer_name='open';
 computer_name | computer_id 
---------------+-------------
 open          |         112
(1 row)

postgres=# select * from computers;                           
 computer_name | computer_id 
---------------+-------------
 cheetah       |         100
 eagle64       |         101
 heron         |         102
 heron64       |         103
 penguin       |         104
 tuna          |         105
 ultravision   |         106
 luke          |         107
 barbara       |         108
 wii           |         109
 silene        |         110
 swan          |         111
 open          |         112

The database is postgresql-9.3.
So the psql command output on the database host is above and the
following PHP code doesn't produce similar results:

...
foreach ( $_POST['computers'] as $setcomp )
{
          chop ($setcomp);

          $query =  "SELECT * FROM computers WHERE computer_name ";
          $query .= "= '$setcomp';";

          echo "$query";

          $result = pg_query($db,$query);
          $compid = pg_fetch_row($result);

          foreach ( $compid as $element )
          { echo "<P>$element</P>"; }

          ...
}

Does the query look wrong in the PHP code???  Looks the same to me...
Note that the computer_id, a three digit number, doesn't come back
correct using the above PHP code.  I get 106 repeated multiple times,
which should never happen.





More information about the svlug mailing list