Received: from localhost (wm.hub.org [200.46.204.128]) by postgresql.org (Postfix) with ESMTP id 3D9919FB5F8 for ; Mon, 9 Oct 2006 10:40:13 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.128]) (amavisd-new, port 10024) with ESMTP id 53903-05 for ; Mon, 9 Oct 2006 13:40:08 +0000 (UTC) X-Greylist: delayed 00:21:56.87378 by SQLgrey- Received: from eastrmmtai09.cox.net (eastrmmtai09.cox.net [68.230.240.50]) by postgresql.org (Postfix) with ESMTP id C74F09FB5EE for ; Mon, 9 Oct 2006 10:40:07 -0300 (ADT) Received: from eastrmwml08.mgt.cox.net ([172.18.52.65]) by eastrmmtao02.cox.net (InterMail vM.6.01.06.01 201-2131-130-101-20060113) with ESMTP id <20061009131809.TZXP10599.eastrmmtao02.cox.net@eastrmwml08.mgt.cox.net>; Mon, 9 Oct 2006 09:18:09 -0400 Message-ID: <7495413.1160399889484.JavaMail.root@eastrmwml08.mgt.cox.net> Date: Mon, 9 Oct 2006 9:18:09 -0400 From: To: "Cyprian Makhafola [ MTN - Innovation Centre ]" Subject: Re: Search an addresbook Cc: pgsql-php@postgresql.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) Sensitivity: Normal X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=4.116 tagged_above=0 required=5 tests=DNS_FROM_RFC_POST, DNS_FROM_RFC_WHOIS, NO_REAL_NAME X-Spam-Level: **** X-Archive-Number: 200610/11 X-Sequence-Number: 3611 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 ""; > 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
$name, $msisdn