Search an addresbook

This is a multi-part message in MIME format.

------_=_NextPart_001_01C6EBA3.016A7C50
Content-Type: text/plain; charset="US-ASCII"
Content-Transfer-Encoding: quoted-printable

Hi All

I am a newby in the php and postgres. I have a the following script that
suppose to search an addrssbook but the scripts does not return anything
even an error. I got this scripts from the internet but in the mysql
form so i changed it to postgres.

The field s for my table is customer_id, name. address, msisdn,
telephone and msisdn. I use want to use name or msisdn to search.
<?php
$dbname =3D "phonebook";
$host =3D "localhost";
$port =3D "5432";
$user =3D "postgres";

if (!IsSet($start) ) :
$start =3D 0;
endif;
?>

<?
#if ($searchstring)
if(isset($searchstring) && strcmp("Search",$searchstring) =3D=3D 0)
{
$query =3D "SELECT * FROM clientdata WHERE $searchtype LIKE
'%$searchstrin
g%' ORDER BY name ASC";
$connection =3D pg_connect("host=3D$host port=3D$port dbname=3D$dbn=
ame
user=3D$use
r");
$pg_select_db("$dbname",$query);
$Customer_id =3D pg_escape_string($_POST['customer_id']);

$Name =3D pg_escape_string($_POST['name']);
$Msisdn =3D pg_escape_string($_POST['msisdn']);
$result =3D pg_query($query);
$resultsnumber =3D pg_numrows($result);

echo "<TABLE BORDER=3D0>";
echo "number of results: $resultsnumber";

$alternate =3D "2";
while ($myrow =3D pg_fetch_array($result))
{
$Name =3D $myrow["name"];
$customer_id =3D $myrow["id"];
$msisdn =3D $myrow["msisdn"];
if ($alternate =3D=3D "1")
{
$color =3D "#ffffff";
$alternate =3D "2";
}
else
{
$color =3D "#efefef";
$alternate =3D "1";
}
echo "<TR bgcolor=3D$color><TD>$name, $msisdn</TD>";
echo "Could not find records";
}
}
?>

I can add and delete but i cannot search, please assist.


NOTE: This e-mail message is subject to the MTN Group disclaimer see http:/=
/www.mtn.co.za/default.aspx?pid=3D34411

------_=_NextPart_001_01C6EBA3.016A7C50
Content-Type: text/html; charset="US-ASCII"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; charset=3Dus-ascii">
<META content=3D"MSHTML 6.00.2900.2963" name=3DGENERATOR></HEAD>
<BODY>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D537065212-09102006>Hi
All</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN
class=3D537065212-09102006></SPAN></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D537065212-09102006>I am a ne=
wby in the
php and postgres. I have a the following script that suppose to search an=
a
ddrssbook but the scripts does not return anything even an error. I got th=
is
scripts from the internet but in the mysql form so i changed it to
postgres.</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN
class=3D537065212-09102006></SPAN></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D537065212-09102006>The field=
s for my
table is customer_id, name. address, msisdn, telephone and msisdn. I use wa=
nt to
use name or msisdn to search.</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN
class=3D537065212-09102006><?php<BR>$dbname     =3D=
"
phonebook";<BR>$host       =3D
"localhost";<BR>$port       =3D
"5432";<BR>$user      =3D "postgres";</SPAN></FONT=
></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D537065212-09102006>if (!IsSe=
t($start) )
:<BR>   $start =3D 0;<BR>endif;<BR>?></SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D537065212-09102006><?<BR>=
#if
($searchstring)<BR>if(isset($searchstring) &&
strcmp("Search",$searchstring) =3D=3D
0)<BR>{<BR>        $query =3D "SELECT * =
FROM
clientdata WHERE $searchtype LIKE '%$searchstrin<BR>g%' ORDER BY name
ASC";<BR>        $connection =3D
pg_connect("host=3D$host port=3D$port dbname=3D$dbname
user=3D$use<BR>r");<BR>       
$pg_select_db("$dbname",$query);<BR>      &nb=
sp;
$Customer_id =3D 
pg_escape_string($_POST['customer_id']);</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2><SPAN
class=3D537065212-09102006>        $Name=
=3D
pg_escape_string($_POST['name']);<BR>      &n=
bsp;
$Msisdn =3D
pg_escape_string($_POST['msisdn']);<BR>      =
 
$result =3D pg_query($query);<BR>       =
$
resultsnumber =3D pg_numrows($result);</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2><SPAN
class=3D537065212-09102006>        echo=
"
<TABLE BORDER=3D0>";<BR>        e=
cho
"number of results: $resultsnumber";</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2><SPAN
class=3D537065212-09102006>        $alte=
rnate =3D
"2";<BR>           &=
nbsp;   
while ($myrow =3D
pg_fetch_array($result))<BR>        =
;       
{<BR>           &nbs=
p;      
$Name =3D
$myrow["name"];<BR>         &n=
bsp;        
$customer_id =3D
$myrow["id"];<BR>         &nbs=
p;        
$msisdn =3D
$myrow["msisdn"];<BR>         =
         
if ($alternate =3D=3D
"1")<BR>           &=
nbsp;      
{<BR>           &nbs=
p;        
$color =3D
"#ffffff";<BR>          &=
nbsp;         
$alternate =3D
"2";<BR>           &=
nbsp;      
}<BR>           &nbs=
p;      
else<BR>           &=
nbsp;      
{<BR>           &nbs=
p;         
$color =3D
"#efefef";<BR>          &=
nbsp;          
$alternate =3D
"1";<BR>           &=
nbsp;      
}<BR>        echo "<TR
bgcolor=3D$color><TD>$name,
$msisdn</TD>";<BR>        echo "Co=
uld
not find
records";<BR>          &n=
bsp;    
}<BR>}<BR>?><BR></SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D537065212-09102006>I can add=
and delete
but i cannot search, p</SPAN></FONT><FONT face=3DArial size=3D2><SPAN
class=3D537065212-09102006>lease assist.</SPAN></FONT></DIV><CODE><FONT SIZ=
E=3D3><BR>
<BR>
NOTE: This e-mail message is subject to the MTN Group disclaimer see http:/=
/www.mtn.co.za/default.aspx?pid=3D34411<BR>
</FONT></CODE></BODY></HTML>

------_=_NextPart_001_01C6EBA3.016A7C50--
Makhaf_C [ Mo, 09 Oktober 2006 15:01 ] [ ID #1493916 ]

Re: Search an addresbook

The PHP gurus have really simplified this issue for us. Both the pg_query() and pg_fetch_array() methods return a false if an error occurs. Likewise, pg_fetch_array() returns a false when it has reached the end of the recordset. The following works very well:

if ($result = pg_query($query) and $row = pg_fetch_array($result)) {
do {
// process query results

} while ($row = pg_fetch_array($result));
} else {
// output if error
}

Best wishes
Mark

On Mon, 2006-10-09 at 15:01 +0200, Cyprian Makhafola [ MTN - Innovation Centre ] wrote:
Hi All I am a newby in the php and postgres. I have a the following script that suppose to search ana ddrssbook but the scripts does not return anything even an error. I got this scripts from the internet but in the mysql form so i changed it to postgres. The field s for my table is customer_id, name. address, msisdn, telephone and msisdn. I use want to use name or msisdn to search. <?php
> $dbname =" phonebook";
> $host = "localhost";
> $port = "5432";
> $user = "postgres"; if (!IsSet($start) ) :
> $start = 0;
> endif;
> ?> <?
> #if ($searchstring)
> if(isset($searchstring) && strcmp("Search",$searchstring) == 0)
> {
> $query = "SELECT * FROM clientdata WHERE $searchtype LIKE '%$searchstrin
> g%' ORDER BY name ASC";
> $connection = pg_connect("host=$host port=$port dbname=$dbname user=$use
> r");
> $pg_select_db("$dbname",$query);
> $Customer_id = pg_escape_string($_POST['customer_id']); $Name = pg_escape_string($_POST['name']);
> $Msisdn = pg_escape_string($_POST['msisdn']);
> $result = pg_query($query);
> $ resultsnumber = pg_numrows($result); echo" <TABLE BORDER=0>";
> echo "number of results: $resultsnumber"; $alternate = "2";
> while ($myrow = pg_fetch_array($result))
> {
> $Name = $myrow["name"];
> $customer_id = $myrow["id"];
> $msisdn = $myrow["msisdn"];
> if ($alternate == "1")
> {
> $color = "#ffffff";
> $alternate = "2";
> }
> else
> {
> $color = "#efefef";
> $alternate = "1";
> }
> echo "<TR bgcolor=$color><TD>$name, $msisdn</TD>";
> echo "Could not find records";
> }
> }
> ?>
>
> I can add and delete but i cannot search, please assist.
>
> NOTE: This e-mail message is subject to the MTN Group disclaimer see http://www.mtn.co.za/default.aspx?pid=34411

---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster
mark.dingee [ Mo, 09 Oktober 2006 15:18 ] [ ID #1493917 ]
Datenbanken » gmane.comp.db.postgresql.php » Search an addresbook

Vorheriges Thema: PDO and PostgreSQL's LISTEN/NOTIFY
Nächstes Thema: Select Where using character varying ??