note 66040 added to function.pg-query

From: Date: Sat, 13 May 2006 01:56:14 +0000
Subject: note 66040 added to function.pg-query
Groups: php.notes 
Request: Send a blank email to php-notes+get-111200@lists.php.net to get a copy of this message
Improving upon what jsuzuki said: It's probably better to use pg_num_rows() to see if no rows were returned, as that leaves the resultset cursor pointed to the first row so you can use it in a loop. Example: <?php $result=pg_query($conn, "SELECT * FROM x WHERE a=b;"); if (!$result) { echo "query did not execute"; } if (pg_num_rows($result) == 0) { echo "0 records" } else { while ($row = pg_fetch_array($result) { //do stuff with $row } } ?> I, personally, also find it more readable. ---- Server IP: 64.71.164.2 Probable Submitter: 68.34.115.109 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.pg-query.php Edit -- http://master.php.net/note/edit/66040 Del: integrated -- http://master.php.net/note/delete/66040/integrated Del: useless -- http://master.php.net/note/delete/66040/useless Del: bad code -- http://master.php.net/note/delete/66040/bad+code Del: spam -- http://master.php.net/note/delete/66040/spam Del: non-english -- http://master.php.net/note/delete/66040/non-english Del: in docs -- http://master.php.net/note/delete/66040/in+docs Del: other reasons-- http://master.php.net/note/delete/66040 Reject -- http://master.php.net/note/reject/66040 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#111200) next »