Reputation: 340
So I have this code:
foreach ($_SESSION['basket'] as $item) {
$ref = $_SESSION['basket'][$counter];
$result = pg_query ($conn, 'SELECT * from music WHERE ref='.$ref.' ORDER BY artist');
}
This will output the first row fine, however it outputs this Warning: pg_fetch_row() expects parameter 1 to be resource, boolean given
if I try to retrieve more than one row. I don't understand how I'm giving a boolean to parameter 1, this is the code on line 46 where it is getting the error:
($row = pg_fetch_row($result))
Thanks in advance
Upvotes: 0
Views: 850
Reputation: 2101
You can use $row =pg_fetch_array($result)
and then $row['field_name']
to take values out in the foreach loop.
The error may be because your connection variable $conn
does not connect to your database.
Try all possibilities. Thank you.
Upvotes: 1
Reputation: 56
Have a look at the examples in the PHP doc: http://php.net/manual/en/function.pg-query.php.
REMEMBER TO:
In general the PHP docs are a great place, when strugling with the details of the PHP-api's, which are sometimes... Less intuitive than they could be. :-)
Upvotes: 0
Reputation: 2097
If your query fails, pg_query
returns FALSE
. Also, you should use pg_query_params
instead to prevent SQL injection.
Upvotes: 0