Novice Postgres Query Question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Lee Blevins

    Novice Postgres Query Question

    I'm trying to query a postgresql database with PHP.

    I am having a problem when using a WHERE. It works without the WHERE.

    Example:

    $query = "SELECT job_number, customer, desription, archive, date_opened,
    job_status FROM jobs WHERE job_status='In Progress' ";


    Returns this error in browser:


    Warning: pg_result(): Unable to jump to row 28 on PostgreSQL result index 7
    in /usr/local/apache2/htdocs/jobs.html on line 23

    Warning: pg_result(): Unable to jump to row 28 on PostgreSQL result index 7
    in /usr/local/apache2/htdocs/jobs.html on line 24

    Warning: pg_result(): Unable to jump to row 28 on PostgreSQL result index 7
    in /usr/local/apache2/htdocs/jobs.html on line 24

    Warning: pg_result(): Unable to jump to row 28 on PostgreSQL result index 7
    in /usr/local/apache2/htdocs/jobs.html on line 25

    Warning: pg_result(): Unable to jump to row 28 on PostgreSQL result index 7
    in /usr/local/apache2/htdocs/jobs.html on line 26

    Warning: pg_result(): Unable to jump to row 28 on PostgreSQL result index 7
    in /usr/local/apache2/htdocs/jobs.html on line 27

    Warning: pg_result(): Unable to jump to row 28 on PostgreSQL result index 7
    in /usr/local/apache2/htdocs/jobs.html on line 28


    The full code I'm using is listed below: (with bad indents from newsreader)



    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Jobs Display</title>
    </head>
    <body>
    <div id="content" class="feature" >
    <table width="800" border="0">

    <?php
    include("jobs_m asthead.html");

    $db_handle = pg_connect("dbn ame=test user=postgres password=1234") ;

    if( $db_handle ) {
    $query = "SELECT job_number, customer, desription, archive,
    date_opened, job_status FROM jobs WHERE job_status='In Progress' ";
    $result = pg_exec($db_han dle, $query);
    if ( pg_numrows($res ult) != 0 ) {
    for( $row = 0; $row < 40; $row++ ) {
    print '<tr>';
    print '<td class="borderce ll" width="5%" ><input
    type="checkbox" name="checkbox" value="checkbox "></td>';
    print '<td class="borderce ll" width="10%" >' . substr(
    pg_result( $result, $row, 'job_number'), 0, 2) . "-" .
    substr( pg_result( $result, $row, 'job_number'), 3, 4) . "-"
    .. substr( pg_result( $result, $row, 'job_number'), 7, 2) . '</td>';
    print '<td class="borderce ll" width="25%" >' . pg_result(
    $result, $row, 'customer' ) . '</td>';
    print '<td class="borderce ll" width="40%" >' . pg_result(
    $result, $row, 'desription' ). '</td>';
    print '<td class="borderce ll" align="center" width="6" >' .
    pg_result( $result, $row, 'archive' ) . '</td>';
    print '<td class="borderce ll" width="6" >' . pg_result(
    $result, $row, 'date_opened' ) . '</td>';
    print '<tr>';
    }
    } else {
    print "There is no result.<br>";
    }
    } else {
    print "No db_handle was made.<br>";
    }
    // print "Closing the db_handle.<br>" ;
    pg_close($db_ha ndle);

    ?>

    </table>

    </body>
    </html>

Working...