RE: [PHP] pg_fetch_array etc
| From: | Dave VanAuken | Date: | Sat, 16 Dec 2000 01:01:33 +0000 |
| Subject: | RE: [PHP] pg_fetch_array etc | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-30628@lists.php.net to get a copy of this message | ||
suspect that this is your culprit liine
while ($Row = pg_fetch_row($Result, $Row))
I have never been able to get potsgress to work that way, though I see that
code alot for MySQL implementation... suspect it has to do with the way PHP
supports postgres vs php supports MySQL
here is a replacement set based on your provided code (over commented), give
it a copy paste and try.
<?
$query = getenv("QUERY_STRING");
parse_str($query);
if ( $query != "" ){
$Query = "select * from generator where ";
$Query .= "orientation LIKE'%$orientation%' and category";
$Query .= " LIKE '%$category%' and keywords LIKE '%$keywords%' ";
$Connection = pg_connect("", "", "", "",
"aaron"); #assuming you have
values
$Result = pg_exec($Connection, $Query);
$RowTotal=pg_numrows($Result); #could add this in while
# statement and remove if block if not
# error checking
if($RowTotal<1) {
echo 'Error - No Results!';
} else {
$RowCount=0;
while ($RowCount<pg_numrows($Result)) {
$Row = pg_fetch_row($Result, $RowCount);
print("$Row[0], $Row[1], $Row[2], $Row[3]<br>\n");
$RowCount++;
} #end loop
pg_freeresult($Result);
pg_close($Connection);
} #end result check if
} #end query if
?>
top of head, not checked - you are forewarned ;)
Dave
-----Original Message-----
From: Dan Harrington [mailto:dan@harringtons.net]
Sent: Saturday, December 16, 2000 1:58 PM
To: php-general@lists.php.net
Subject: [PHP] pg_fetch_array etc
Hello,
I'm using PHP to grab some rows off a PostgreSQL server and return the
results....and for some reason this code
keeps looping and looping and looping forever when called from a webpage as
follows:
http://www.myservername.com/database.php?orientation=both&category=nature&ke
ywords=water+fire
I know that just 1 row results....
select * from generator where orientation like '%both%' and category like
'%nature%' and keywords like '%water%' and keywords like '%
fire%';
----------------------------------------------------------------------------
---------------------------
clip | title | image | height | width | orientation |
artist | keywords | quality | category | prints
------+----------------+--------------------+--------+-------+-------------+
--------+----------------------+---------+----------+--------
| Flaming Person | images/flaming.gif | 133 | 200 | both |
| water fire earth air | | nature |
(1 row)
----------------------------------------------------------------------------
---------------------------
and here is the code . . . why in the heck ?
<?
$query = getenv("QUERY_STRING");
parse_str($query);
if ( $query != "" )
{
$Query = "select * from generator where ";
$Query .= "orientation LIKE'%$orientation%' and category";
$Query .= " LIKE '%$category%' and keywords LIKE '%$keywords%'
";
$Connection = pg_connect("", "", "", "",
"aaron");
$Result = pg_exec($Connection, $Query);
while ($Row = pg_fetch_row($Result, $Row))
{
print("$Row[0], $Row[1], $Row[2], $Row[3]<br>\n");
}
}
pg_freeresult($Result);
pg_close($Connection);
?>
-------------
I'm aware that I should strip certain characters right after I
genenv("QUERY_STRING") for security's sake...I just
want the stupid thing to work before I implement those features.
Why does it loop forever?
Thanks
Dan Harrington
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
For additional commands, e-mail: php-general-help@lists.php.net
To contact the list administrators, e-mail: php-list-admin@lists.php.net