Vexing PHP problem - browser hangs.

Vexing PHP problem - browser hangs.

am 16.07.2003 22:44:30 von Lynna Landstreet

Hi folks,

I'm running into trouble with a bit of PHP code that ought to be simple and
probably is to anyone who actually knows what they're doing, but is causing
my browser to hang every time I run it. The script in question follows; it's
supposed to query the artists table in my database and print a list of all
the artists, one per line, last name then first name. It also pulls up the
artist_id field because once I've gotten the damn thing to work at all, I'm
going to use that to link the names to artist info pages, but right now that
field isn't being used.

I know the connection to the database (which happens in the head section of
the document, not here) is being made successfully, because I tested that on
its own first. And the query is being made successfully, because I tested
that to, before I added the code to display the artists' names. It's that
part that is causing it to hang. I don't get any error message or anything,
the browser just "thinks" for an eternity, locking up my system while doing
so, until I eventually force-quit it.

Does anyone have any idea what might be going wrong? There is a fairly large
number of artist records (around 500), but I don't think that's it, because
when I tried changing the second expression in the for statement to row < 30
instead of row < pg_numrows($artist_list) to just print the first 30 names,
it didn't help. I'm hoping the problem is something simply that a more
experienced person could see easily and I'm just missing because I'm new at
this...

Anyway, here's the code. BTW, the server has PostgreSQL 7.2 and PHP 4.1, so
some of the names of the PHP functions are different than they would be in
4.2.


// queries the database, finds artists

$query = "SELECT artist_id, firstname, lastname FROM artists
ORDER BY lastname";
$artist_list = pg_exec($db, $query);
if ($artist_list) {

// checks to see if any results where found

if ( pg_numrows($artist_list) == 0) {
echo "

Sorry, no artists were found.

";
} else {

// writes list

for ($row = 0; row < pg_numrows($artist_list); $row++) {
echo "

" . pg_result($artist_list, $row,
'lastname') . ", " . pg_result($artist_list, $row, 'firstname') . "

";
}

// adds total to bottom of list

echo "

Total results retrieved:" .
pg_numrows($artist_list) . "

";

}

// prints error message if query fails

} else {
echo "

The query failed with the following error
message:

";
echo "

" . pg_errormessage($db) . "

";
}
?>

Thanks,

Lynna
--
Resource Centre Database Coordinator
Gallery 44
www.gallery44.org


---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Re: Vexing PHP problem - browser hangs.

am 16.07.2003 23:09:57 von Frank Bax

At 04:44 PM 7/16/03, Lynna Landstreet wrote:
> for ($row = 0; row < pg_numrows($artist_list); $row++) {


row should be $row


---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Re: Vexing PHP problem - browser hangs.

am 16.07.2003 23:14:39 von Joe Conway

Lynna Landstreet wrote:
> for ($row = 0; row < pg_numrows($artist_list); $row++) {

Make this line read:
for ($row = 0; $row < pg_numrows($artist_list); $row++) {

Note the missing "$" on row at "row < pg_numrows".

HTH,

Joe




---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Re: Vexing PHP problem - browser hangs.

am 16.07.2003 23:28:59 von Lynna Landstreet

on 7/16/03 5:09 PM, Frank Bax at fbax@sympatico.ca wrote:

>> for ($row = 0; row < pg_numrows($artist_list); $row++) {
>
> row should be $row

Aaauuuggghhh!!! That would be it. How did I not notice that?

*sigh* I thought it would turn out to be something simple...

Many thanks, to all who pointed that out. Works fine now.


Lynna
--
Resource Centre Database Coordinator
Gallery 44
www.gallery44.org


---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org

Re: Vexing PHP problem - browser hangs.

am 17.07.2003 00:11:17 von Steve Crawford

Be aware that $artist_list is an array (rows) of arrays (columns in each row).

For your version of php you need to first get the row with
$thisrow = pg_fetch_row($artist_list, $row)
and then get the fields from the row array with
$thisrow[0], $thisrow[1]...

See: http://us2.php.net/manual/en/function.pg-fetch-row.php

Cheers,
Steve



On Wednesday 16 July 2003 1:44 pm, Lynna Landstreet wrote:
> Hi folks,
>
> I'm running into trouble with a bit of PHP code that ought to be simple and
> probably is to anyone who actually knows what they're doing, but is causing
> my browser to hang every time I run it. The script in question follows;
> it's supposed to query the artists table in my database and print a list of
> all the artists, one per line, last name then first name. It also pulls up
> the artist_id field because once I've gotten the damn thing to work at all,
> I'm going to use that to link the names to artist info pages, but right now
> that field isn't being used.
>
> I know the connection to the database (which happens in the head section of
> the document, not here) is being made successfully, because I tested that
> on its own first. And the query is being made successfully, because I
> tested that to, before I added the code to display the artists' names. It's
> that part that is causing it to hang. I don't get any error message or
> anything, the browser just "thinks" for an eternity, locking up my system
> while doing so, until I eventually force-quit it.
>
> Does anyone have any idea what might be going wrong? There is a fairly
> large number of artist records (around 500), but I don't think that's it,
> because when I tried changing the second expression in the for statement to
> row < 30 instead of row < pg_numrows($artist_list) to just print the first
> 30 names, it didn't help. I'm hoping the problem is something simply that a
> more experienced person could see easily and I'm just missing because I'm
> new at this...
>
> Anyway, here's the code. BTW, the server has PostgreSQL 7.2 and PHP 4.1, so
> some of the names of the PHP functions are different than they would be in
> 4.2.
>
> >
> // queries the database, finds artists
>
> $query = "SELECT artist_id, firstname, lastname FROM artists
> ORDER BY lastname";
> $artist_list = pg_exec($db, $query);
> if ($artist_list) {
>
> // checks to see if any results where found
>
> if ( pg_numrows($artist_list) == 0) {
> echo "

Sorry, no artists were found.

";
> } else {
>
> // writes list
>
> for ($row = 0; row < pg_numrows($artist_list); $row++) {
> echo "

" . pg_result($artist_list, $row,
> 'lastname') . ", " . pg_result($artist_list, $row, 'firstname') . "

";
> }
>
> // adds total to bottom of list
>
> echo "

Total results retrieved:" .
> pg_numrows($artist_list) . "

";
>
> }
>
> // prints error message if query fails
>
> } else {
> echo "

The query failed with the following error
> message:

";
> echo "

" . pg_errormessage($db) . "

";
> }
> ?>
>
> Thanks,
>
> Lynna


---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Re: Vexing PHP problem - browser hangs.

am 17.07.2003 09:52:16 von adriantineo

Every time a script has hung on me it was because of a badly written loop.
The first time I took some time to notice but you'll see that's about the
only situation you could hang the browser.

Adrian Tineo

>
> Aaauuuggghhh!!! That would be it. How did I not notice that?
>
> *sigh* I thought it would turn out to be something simple...
>
> Many thanks, to all who pointed that out. Works fine now.



---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo@postgresql.org)

Re: Vexing PHP problem - browser hangs.

am 17.07.2003 20:24:39 von David Busby

try:
ini_set("error_reporting",E_ALL);
ini_set("display_errors",1);

http://www.php.net/manual/en/function.ini-set.php

Requires code more stricter.

/B

----- Original Message -----
From: "Steve Crawford"
To: "Lynna Landstreet" ;
Sent: Wednesday, July 16, 2003 15:11
Subject: Re: [PHP] Vexing PHP problem - browser hangs.


> Be aware that $artist_list is an array (rows) of arrays (columns in each
row).
>
> For your version of php you need to first get the row with
> $thisrow = pg_fetch_row($artist_list, $row)
> and then get the fields from the row array with
> $thisrow[0], $thisrow[1]...
>
> See: http://us2.php.net/manual/en/function.pg-fetch-row.php
>
> Cheers,
> Steve
>
>
>
> On Wednesday 16 July 2003 1:44 pm, Lynna Landstreet wrote:
> > Hi folks,
> >
> > I'm running into trouble with a bit of PHP code that ought to be simple
and
> > probably is to anyone who actually knows what they're doing, but is
causing
> > my browser to hang every time I run it. The script in question follows;
> > it's supposed to query the artists table in my database and print a list
of
> > all the artists, one per line, last name then first name. It also pulls
up
> > the artist_id field because once I've gotten the damn thing to work at
all,
> > I'm going to use that to link the names to artist info pages, but right
now
> > that field isn't being used.
> >
> > I know the connection to the database (which happens in the head section
of
> > the document, not here) is being made successfully, because I tested
that
> > on its own first. And the query is being made successfully, because I
> > tested that to, before I added the code to display the artists' names.
It's
> > that part that is causing it to hang. I don't get any error message or
> > anything, the browser just "thinks" for an eternity, locking up my
system
> > while doing so, until I eventually force-quit it.
> >
> > Does anyone have any idea what might be going wrong? There is a fairly
> > large number of artist records (around 500), but I don't think that's
it,
> > because when I tried changing the second expression in the for statement
to
> > row < 30 instead of row < pg_numrows($artist_list) to just print the
first
> > 30 names, it didn't help. I'm hoping the problem is something simply
that a
> > more experienced person could see easily and I'm just missing because
I'm
> > new at this...
> >
> > Anyway, here's the code. BTW, the server has PostgreSQL 7.2 and PHP 4.1,
so
> > some of the names of the PHP functions are different than they would be
in
> > 4.2.
> >
> > > >
> > // queries the database, finds artists
> >
> > $query = "SELECT artist_id, firstname, lastname FROM artists
> > ORDER BY lastname";
> > $artist_list = pg_exec($db, $query);
> > if ($artist_list) {
> >
> > // checks to see if any results where found
> >
> > if ( pg_numrows($artist_list) == 0) {
> > echo "

Sorry, no artists were found.

";
> > } else {
> >
> > // writes list
> >
> > for ($row = 0; row < pg_numrows($artist_list); $row++)
{
> > echo "

" . pg_result($artist_list, $row,
> > 'lastname') . ", " . pg_result($artist_list, $row, 'firstname') .
"

";
> > }
> >
> > // adds total to bottom of list
> >
> > echo "

Total results retrieved:" .
> > pg_numrows($artist_list) . "

";
> >
> > }
> >
> > // prints error message if query fails
> >
> > } else {
> > echo "

The query failed with the following error
> > message:

";
> > echo "

" . pg_errormessage($db) . "

";
> > }
> > ?>
> >
> > Thanks,
> >
> > Lynna
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster


---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Re: Vexing PHP problem - browser hangs.

am 17.07.2003 21:12:53 von Frank Finner

Hi!

On Thu, 17 Jul 2003 11:24:39 -0700 "David Busby" sat
down, thought long and then wrote:

> for ($row =3D 0; row < pg_numrows($artist_list)

You left out a $ sign in the line above. Should be "$row <
pg_numrows($artist_list)", otherwise "row" is either == 0 or undefined
(don=B4t know exactly).

Greetings,
--=20
Frank Finner

Memory follows memory, memory defeats memory; some things are banished
only into the realms of our rich imaginings - but this does not mean
that they do not or cannot or will not exist - they exist! They exist!
(M. Moorcock, "The Revenge Of The Rose")

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org

Fw: Re: Vexing PHP problem - browser hangs.

am 17.07.2003 21:14:24 von Frank Finner

Sorry, if this comes twice, in the first try I used the wrong account
for the list.

Hi!

On Thu, 17 Jul 2003 11:24:39 -0700 "David Busby" sat
down, thought long and then wrote:

> for ($row =3D 0; row < pg_numrows($artist_list)

You left out a $ sign in the line above. Should be "$row <
pg_numrows($artist_list)", otherwise "row" is either == 0 or undefined
(don=B4t know exactly).

Greetings,
--=20
Frank Finner

Memory follows memory, memory defeats memory; some things are banished
only into the realms of our rich imaginings - but this does not mean
that they do not or cannot or will not exist - they exist! They exist!
(M. Moorcock, "The Revenge Of The Rose")

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html