$name, $msisdn | ";
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
Hi=20
All
class=3D537065212-09102006>
I am a ne=
wby in the=20
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=20
scripts from the internet but in the mysql form so i changed it to=20
postgres.
class=3D537065212-09102006>
The field=
s for my=20
table is customer_id, name. address, msisdn, telephone and msisdn. I use wa=
nt to=20
use name or msisdn to search.
class=3D537065212-09102006><?php
$dbname =3D=
"
phonebook";
$host =
"localhost";
$port =
"5432";
$user =3D "postgres";
>
if (!IsSe=
t($start) )=20
:
$start =3D 0;
endif;
?>
<?
=
#if=20
($searchstring)
if(isset($searchstring) &&=20
strcmp("Search",$searchstring) ===20
0)
{
$query =3D "SELECT * =
FROM=20
clientdata WHERE $searchtype LIKE '%$searchstrin
g%' ORDER BY name=20
ASC";
$connection =
pg_connect("host=3D$host port=3D$port dbname=3D$dbname=20
user=3D$use
r");
=20
$pg_select_db("$dbname",$query);
&nb=
sp;=20
$Customer_id =3D =20
pg_escape_string($_POST['customer_id']);
class=3D537065212-09102006> $Name=
=
pg_escape_string($_POST['name']);
&n=
bsp;=20
$Msisdn =
pg_escape_string($_POST['msisdn']);
=
=20
$result =3D pg_query($query);
=
$
resultsnumber =3D pg_numrows($result);
class=3D537065212-09102006> echo=
"
<TABLE BORDER=3D0>";
e=
cho=20
"number of results: $resultsnumber";
class=3D537065212-09102006> $alte=
rnate =
"2";
&=
nbsp; =20
while ($myrow =
pg_fetch_array($result))
 =
; =20
{
&nbs=
p; =20
$Name =
$myrow["name"];
&n=
bsp; =20
$customer_id =
$myrow["id"];
&nbs=
p; =20
$msisdn =
$myrow["msisdn"];
=
=20
if ($alternate ===20
"1")
&=
nbsp; =20
{
&nbs=
p; =20
$color =
"#ffffff";
&=
nbsp; =20
$alternate =
"2";
&=
nbsp; =20
}
&nbs=
p; =20
else
&=
nbsp; =20
{
&nbs=
p; =20
$color =
"#efefef";
&=
nbsp; =20
$alternate =
"1";
&=
nbsp; =20
}
echo "<TR=20
bgcolor=3D$color><TD>$name,=20
$msisdn</TD>";
echo "Co=
uld=20
not find=20
records";
&n=
bsp; =20
}
}
?>
I can add=
and delete=20
but i cannot search, p
class=3D537065212-09102006>lease assist.
E=3D3>
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--
Re: Search an addresbook
am 09.10.2006 15:18:09 von mark.dingee
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.
> $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"
";
> 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 "$name, $msisdn | ";
> 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