forms /selects

forms /selects

am 10.12.2002 13:29:38 von angelo.rigo

Hi all

I am trying to do a select from a table after the user has choosen the first
letter of the name and it must display only the names with that letter sele=
cted
in a select box. The message i get is if i select a for example is:
"the atribute 'a' not found"

I would like some help to know what?s going wrong!
Thank?s in advance

=C2ngelo Rigo

Here is my code:

Search names by the first letter

?>">




$db =3D pg_connect("dbname=3Ddb user=3Duser");
$query =3D"SELECT name FROM thetable WHERE (nome=3D$leter%) ORDER BY nome A=
SC
";
$result =3D pg_exec($db, $query);

if (!$result) {printf ("Error!"); exit;}
$numrows =3D pg_numrows($result);
$row=3D0;
printf ("");
printf ("");
do
{
$myrow =3D pg_fetch_array ($result,$row);
if($row % 2) {
$bgcolor=3D"#FFFF99";
}
else {
$bgcolor=3D"";
}
printf ("",$myrow[nome]);
$row++;
}
while ($row < $numrows);
printf ("
Name
%s
");
pg_close($db);
?>

________________________________________
A busca mais veloz e precisa da internet. Acesse agora: http://www.zoom.com=
..br.



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

http://archives.postgresql.org

Re: forms /selects

am 10.12.2002 15:03:33 von jco

This is a multipart message in MIME format.
--=_alternative 004D482BC1256C8B_=
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

I see a couple of errors, one of which is the source of your problem.
You write:
"SELECT name FROM thetable WHERE (nome=3D$leter%) ORDER BY nome ASC=
";
This would evaluate to
"SELECT name FROM thetable WHERE (nome=3DA%) ORDER BY nome ASC";

What you need to write is:
"SELECT name FROM thetable WHERE (nome like '$leter%') ORDER BY nom=
e ASC";

"like" is required to make regular expression match.
The quotes are always required when dealing with strings (and a few other=
=20
types).

You could have just debugged this by
echo $query;

Also: Letter contains two t's. :)

Regards
/J=F8rn Cornelius Olsen
--=_alternative 004D482BC1256C8B_=
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable



I see a couple of errors, one of whi=
ch is the source of your problem.


You write:

        <=
font size=3D2 face=3D"Courier New">"SELECT name FROM thetable WHERE (n=
ome=3D$leter%) ORDER BY nome ASC";

This would evaluate to

        "S=
ELECT name FROM thetable WHERE (nome=3DA%) ORDER BY nome ASC";




What you need to write is:

        "S=
ELECT name FROM thetable WHERE (nome like '$leter%') ORDER BY nome ASC"=
;;




"like" is required to mak=
e regular expression match.


The quotes are always required when=
dealing with strings (and a few other types).




You could have just debugged this b=
y


        echo $q=
uery;




Also: Letter contains two t's. :) font>



Regards

/J=F8rn Cornelius Olsen
--=_alternative 004D482BC1256C8B_=--

Re: forms /selects

am 10.12.2002 17:52:45 von angelo.rigo

Hi

I see my error was not using the "like"
but now i fall in other problem:

I have made an if else to display a message
if have no name with the selected leter as initial

it works but disply too:

Warning: Unable to jump to row 0 on PostgreSQL result index 2 in /var/www/h=
tml/inscricao/resultado_a1.php
on line 80

how could i handle this?

Thank?s in advance:

here is my actual code:

Pesquisa de nome por letra inicial

?>">




$db =3D pg_connect("dbname=3Ddb user=3Duser");
$query =3D"SELECT name FROM aprovados WHERE (nome like '$leter%') ORDER BY
name ASC ";
$result =3D pg_exec($db, $query);

if (!$result) {printf ("N=E3o h=E1 nomes com esta letra inicial!"); exit;}
$numrows =3D pg_numrows($result);


/***********************
actual problem
***********************/

if ($numrows=='0') {
print("N=E3o foram encontrados nomes iniciados por : $letra");
print("");
}
else

$row=3D0;
printf ("");
printf ("");
do
{
$myrow =3D pg_fetch_array ($result,$row);
if($row % 2) {
$bgcolor=3D"#FFFF99";
}
else {
$bgcolor=3D"";
}
printf ("",$myrow[nome]);
$row++;
}
while ($row < $numrows);
printf ("
Nome
%s
");
pg_close($db);
?>






'>'-- Mensagem Original --
'>'To: pgsql-php@postgresql.org
'>'Subject: Re: [PHP] forms /selects
'>'From: jco@cornelius-olsen.dk
'>'Date: Tue, 10 Dec 2002 15:03:33 +0100
'>'
'>'
'>'I see a couple of errors, one of which is the source of your problem.
'>'You write:
'>' "SELECT name FROM thetable WHERE (nome=3D$leter%) ORDER BY nome
ASC";
'>'This would evaluate to
'>' "SELECT name FROM thetable WHERE (nome=3DA%) ORDER BY nome ASC";
'>'
'>'What you need to write is:
'>' "SELECT name FROM thetable WHERE (nome like '$leter%') ORDER
BY nome
'>'ASC";
'>'
'>'"like" is required to make regular expression match.
'>'The quotes are always required when dealing with strings (and a few
other
'>'
'>'types).
'>'
'>'You could have just debugged this by
'>' echo $query;
'>'
'>'Also: Letter contains two t's. :)
'>'
'>'Regards
'>'/J=F8rn Cornelius Olsen


________________________________________
A busca mais veloz e precisa da internet. Acesse agora: http://www.zoom.com=
..br.



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

http://archives.postgresql.org

Re: forms /selects solution

am 10.12.2002 18:19:10 von angelo.rigo

Here is the final working code:



?>">






$db =3D pg_connect("dbname=3Ddb user=3Duser");
$query =3D"SELECT name FROM table WHERE (nome like '$leter%') ORDER BY name
ASC ";
$result =3D pg_exec($db, $query);

if (!$result) {printf ("N=E3o h=E1 nomes com esta letra inicial!"); exit;}
$numrows =3D pg_numrows($result);

if (!$numrows) {
print("N=E3o foram encontrados nomes iniciados por : $letra");
print("");
}
else{
$row=3D0;
printf ("");
printf ("");
do
{
$myrow =3D pg_fetch_array ($result,$row);
if($row % 2) {
$bgcolor=3D"#FFFF99";
}
else {
$bgcolor=3D"";
}
printf ("",$myrow[name]);
$row++;
}
while ($row < $numrows);
printf ("
Nome
%s
");
}//else
pg_close($db);
?>



'>'-- Mensagem Original --
'>'Date: Tue, 10 Dec 2002 13:52:45 -0300
'>'From: angelo.rigo@globo.com
'>'Subject: Re: [PHP] forms /selects
'>'To: pgsql-php@postgresql.org
'>'
'>'
'>'Hi
'>'
'>'I see my error was not using the "like"
'>'but now i fall in other problem:
'>'
'>'I have made an if else to display a message
'>'if have no name with the selected leter as initial
'>'
'>'it works but disply too:
'>'
'>'Warning: Unable to jump to row 0 on PostgreSQL result index 2 in /var/w=
ww/html/inscricao/resultado_a1.php
'>'on line 80
'>'
'>'how could i handle this?
'>'
'>'Thank?s in advance:
'>'
'>'here is my actual code:
'>'
'>'Pesquisa de nome por letra inicial
'>'
");
?>">
'>'

'>'
'>'

'>' '>'$db =3D pg_connect("dbname=3Ddb user=3Duser");
'>'$query =3D"SELECT name FROM aprovados WHERE (nome like '$leter%') ORDER
BY
'>'name ASC ";
'>'$result =3D pg_exec($db, $query);
'>'
'>'if (!$result) {printf ("N=E3o h=E1 nomes com esta letra inicial!"); exi=
t;}
'>'$numrows =3D pg_numrows($result);
'>'
'>'
'>'/***********************
'>' actual problem
'>'***********************/
'>'
'>'if ($numrows=='0') {
'>' print("N=E3o foram encontrados nomes iniciados por : $letra");
'>' print("");
'>'}
'>'else
'>'
'>'$row=3D0;
'>'printf ("");
'>'printf ("");
'>'do
'>'{
'>'$myrow =3D pg_fetch_array ($result,$row);
'>' if($row % 2) {
'>' $bgcolor=3D"#FFFF99";
'>' }
'>' else {
'>' $bgcolor=3D"";
'>' }
'>'printf ("",$myrow[nome]);
'>'$row++;
'>'}
'>'while ($row < $numrows);
'>'printf ("
Nome
%s
");
'>'pg_close($db);
'>'?>
'>'
'>'
'>'
'>'
'>'
'>'
'>' '>'-- Mensagem Original --
'>' '>'To: pgsql-php@postgresql.org
'>' '>'Subject: Re: [PHP] forms /selects
'>' '>'From: jco@cornelius-olsen.dk
'>' '>'Date: Tue, 10 Dec 2002 15:03:33 +0100
'>' '>'
'>' '>'
'>' '>'I see a couple of errors, one of which is the source of your proble=
m.
'>' '>'You write:
'>' '>' "SELECT name FROM thetable WHERE (nome=3D$leter%) ORDER BY
nome
'>'ASC";
'>' '>'This would evaluate to
'>' '>' "SELECT name FROM thetable WHERE (nome=3DA%) ORDER BY nome
ASC";
'>' '>'
'>' '>'What you need to write is:
'>' '>' "SELECT name FROM thetable WHERE (nome like '$leter%') ORDER
'>'BY nome
'>' '>'ASC";
'>' '>'
'>' '>'"like" is required to make regular expression match.
'>' '>'The quotes are always required when dealing with strings (and a
few
'>'other
'>' '>'
'>' '>'types).
'>' '>'
'>' '>'You could have just debugged this by
'>' '>' echo $query;
'>' '>'
'>' '>'Also: Letter contains two t's. :)
'>' '>'
'>' '>'Regards
'>' '>'/J=F8rn Cornelius Olsen
'>'
'>'
'>'________________________________________
'>'A busca mais veloz e precisa da internet. Acesse agora: http://www.zoom=
..com.br.
'>'
'>'
'>'
'>'---------------------------(end of broadcast)---------------------------
'>'TIP 6: Have you searched our list archives?
'>'
'>'http://archives.postgresql.org


________________________________________
A busca mais veloz e precisa da internet. Acesse agora: http://www.zoom.com=
..br.



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