pg_emp_fetch_row1.txt
Note : A descending list of maneuvering records, in order of efficient uses on a web page.
  • pg_fetch_row() fetches one row of data from the result associated with the specified result resource.
  • pg_fetch_array() is an extended version of pg_fetch_row(). In addition to storing the data in the numeric indices (field number) to the result array, it can also store the data using associative indices (field name). It stores both indicies by default.
     
    $emp_array = pg_fetch_array($result, 0, PGSQL_NUM);
    echo "eid::".$emp_array [0] . " || ";
    echo "fname:: ".$emp_array [1] . " || ";
    echo "lname ::".$emp_array [2] . " ||";
    echo "address:: ".$emp_array [3] . "  <br/>";
    echo "----------PGSQL_ASSOC-----------------<br/>";
    $arr = pg_fetch_array($result, NULL, PGSQL_ASSOC);
    echo "emp fname :". $arr["fname"] ;
    echo "&nbsp : emp lname :".$arr["lname"]." ";
    echo "&nbsp : emp address :".$arr["address"]." <br/>";
    echo "emp fname :". $arr["fname"] ;
    echo "&nbsp : emp lname :".$arr["lname"]." ";
    echo "&nbsp : emp address :".$arr["address"]." <br/>";
  • pg_fetch_result($result): string pg_fetch_result ( resource $result , int $row , mixed $field )
    Returns a particular row

    for ($row = 0; $row < pg_num_rows($result); $row++) {
    //embbedding for loop
    echo "<tr/>";
    for($y=0; $y < pg_num_fields($result) ; $y++)
    {
    $r2 = pg_fetch_result($result, $row, $y);
    echo " <td class='td2'>".$r2."</td>";
    } // nested for
    echo "</tr>";

    }
    echo "</table>";
  • pg_fetch_assoc: can be used with distinct field/column name.
    while ($row = pg_fetch_assoc($result)) {
    echo $row['id'];
    echo $row['author'];
    echo $row['email'];
    }
  • pg_fetch_object($result)
 
echo"<br/><table border='1'>";
//
for ($row = 0; $row < pg_num_rows($result); $row++) {
$values = pg_fetch_row($result, $row);
echo "<tr><td>";
echo implode(' ', $values) . "</td></tr>\n";
}
echo "</table>";
Note: pg_fetch_row returns single row at a time: